【发布时间】:2023-03-23 02:29:01
【问题描述】:
我有一个如下所示的期望脚本:
#!/usr/bin/expect
set path_start [lindex $argv 0]
set host [lindex $argv 1]
spawn ssh root@$host telnet jpaxdp
expect {\-> }
set fh [open ${path_start}${host} r]
while {[gets $fh line] != -1} {
send "$line\r"
expect {\-> }
}
close $fh
send "exit\r"
expect eof
我将其称为 ./script.sh cmds_ cc1,现在我的主机编号为 1 - 8,我尝试将脚本称为 ./script cmds_ cc[1-8],但这不起作用,因为脚本解释了 host[1-8] 作为论据并向我展示:
spawn ssh root@cc[1-8] telnet jpaxdp
ssh: Could not resolve hostname cc[1-8]: Name or service not known
couldn't open "cmds_cc[1-8]": no such file or directory
while executing
"open ${path_start}${host} r"
invoked from within
"set fh [open ${path_start}${host} r]"
(file "./script.sh" line 7)
我怎样才能做到这一点?
【问题讨论】:
-
这是一个 Expect 脚本,而不是 bash 脚本。
-
可能有一个命令行实用程序会递归地执行这样的调用。如果快速谷歌搜索没有从 Linux 中找到任何内容,我会推荐另一个脚本。
标签: linux bash shell ssh expect