期望脚本自己终止



我已经写了下面的预期脚本,但它没有像预期的那样工作。我希望脚本在执行所有命令时自动终止。但是,脚本要么永远不会终止(如果使用set timeout -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 "$passwordr"
send "$PWDr"
sleep 1
for {set i 0} {$i<[array size cmdstr]} {incr i} {
send "$cmdstr($i)r"
}
send "exitr"
expect eof
}

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

最新更新