[英]How can I call an expect script with a sequence of arguments
I have an expect script that looks like: 我有一个期望脚本,看起来像:
#!/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
and I call it like ./script.sh cmds_ cc1
, now my hosts are numbered 1 - 8 and I tried to call the script like ./script cmds_ cc[1-8]
but that didn't work as the script interpreted host[1-8] as argument and showed me: 我将其命名为./script.sh cmds_ cc1
,现在我的主机编号为1-8,我尝试调用./script cmds_ cc[1-8]
之类的脚本,但该脚本无法作为脚本解释的主机[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)
How can I make this work? 我该如何进行这项工作?
cc[1-8]
is a filename wildcard, it looks for files that match that pattern. cc[1-8]
是文件名通配符,它将查找与该模式匹配的文件。 If there aren't any, the wildcard itself is kept in the argument list. 如果没有,通配符本身将保留在参数列表中。 To get a range of numbers, use cc{1..8}
. 要获取一定范围的数字,请使用cc{1..8}
。 And to run the command repeatedly, you need a for
loop. 要重复运行该命令,您需要一个for
循环。
for host in cc{1..8}
do
./script.sh cmds_ "$host"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.