我有一个expect脚本,看起来像:
#!/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]
那样调用脚本,但这不起作用,因为脚本将host1-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)
我怎么才能把这事做好?
发布于 2016-08-12 19:45:54
cc[1-8]
是一个文件名通配符,它查找与该模式匹配的文件。如果没有,则通配符本身保存在参数列表中。要获得一系列数字,请使用cc{1..8}
。要重复运行该命令,您需要一个for
循环。
for host in cc{1..8}
do
./script.sh cmds_ "$host"
done
https://stackoverflow.com/questions/38925392
复制相似问题