【问题标题】:setting expect variable with grep output使用 grep 输出设置期望变量
【发布时间】:2014-08-08 21:32:08
【问题描述】:

我使用一个expect脚本登录到远程服务器;为此,我需要设置 2 个变量:

set username <user>
set password <passwd>

我从文件中 grep userpasswd。如何使用 grep ouptut 设置期望变量?

当我尝试时:

set username "grep '(?<=username:)[^<]*' file"
set password "grep '(?<=password:)[^<]*' file"

期待说:

无效的命令名称“^

"发送"grep -oP '(?

(文件“./test”第 11 行)

当我尝试时:

set username "grep -oP '(?<=username:)[\^\<]*' file)" 

期待说:

无法读取“(grep -oP '(?

没有这样的变量 执行时

"发送 "$(grep -oP '(?

(文件“./test”第 11 行)

我只是想知道什么是正确的语法。

【问题讨论】:

  • 我不知道答案,但我认为你需要set password [exec &lt;yourcommand&gt;]

标签: grep expect


【解决方案1】:

你会想要这样的:

set fid [open file r]
set contents [read $fid]
close $fid
lassign [regexp -inline {username:([^<]+)} $contents] x username
lassign [regexp -inline {password:([^<]+)} $contents] x password

您在使用 Tcl 语法时遇到了困难,所以从 Tcl tutorial 开始。

【讨论】:

    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    • 2021-05-27
    • 2014-09-06
    • 2016-03-17
    • 1970-01-01
    相关资源
    最近更新 更多