我有一个期望脚本,看起来像:
#!/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 "$liner"
expect {-> }
}
close $fh
send "exitr"
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)
我怎样才能使它工作?
cc[1-8]
是一个文件名通配符,它查找与该模式匹配的文件。如果没有,则通配符本身保留在参数列表中。要获得一个数字范围,使用cc{1..8}
。为了重复运行该命令,您需要一个for
循环。
for host in cc{1..8}
do
./script.sh cmds_ "$host"
done