0
这是我期望在shell中的代码。我想从命令获得输出到shell中的变量expect
#!/usr/bin/expect -f
array set routers { 0 "192.168.1.1" 1 "127.0.0.1"}
array set password { 0 "56343451" 1 "123456789" }
set size 2
set COUNT 10
for {set i 0} {$i < $size} {incr i 1} {
set count "[ping -c $COUNT $routers($i) | grep 'received' | awk -F',' '{ print \$2 }' | awk '{ print \$1 }']"
if { $count <= 3 } {
spawn ssh [email protected]$routers($i)
expect { "no)?" { send "yes\r"; exp_continue }
password: { send $password($i)"\r"; exp_continue}
interact
}
}
}
我想从ping输出接收到$ count。 当我尝试运行,这是发生“‘:没有这样的文件或目录’