期待脚本自行终止

时间:2013-03-13 12:49:13

标签: expect

我写了下面的期望脚本,但它没有按预期工作。我希望脚本在执行所有命令时自动终止。但是,脚本要么永远不会终止(如果使用设置超时-1),要么在执行命令之前在几秒钟内终止。有人可以帮忙吗?

这是脚本:

#!/usr/local/bin/expect

spawn su vserve
set password vserve
set PWD whoami

set cmdstr(0) "bash /apps/vpn/vserve/vserve_profile"
set cmdstr(1) "bash /apps/vpn/asap/scripts/change_loopback.sh"
set timeout -1
expect "*Password:*" {
sleep 1
send "$password\r"
send "$PWD\r"
sleep 1

for {set i 0} {$i<[array size cmdstr]} {incr i} {
send "$cmdstr($i)\r"

}

send \"exit\r\"
expect eof
}

1 个答案:

答案 0 :(得分:1)

通常在交互式shell中,在expect下一个命令之前,必须send特定的shell提示符。这就是我们确保前一个命令真正完成的方式。

相关问题