expect的脚本交互异常并且卡死
expect脚本如下所示:
clean_env.exp:
#!/usr/bin/expect
set LOCAL_TYPE [lindex $argv 0]
set FTP_ROOT [lindex $argv 1]
set IP [lindex $argv 2]
set HANDLE [lindex $argv 3]
set USRNAME [lindex $argv 4]
set PASSWD [lindex $argv 5]
set timeout 420
spawn /usr/bin/ssh $USRNAME@$IP
expect {
"(yes/no)?" {send "yes\r"; exp_continue}
"Password" {send "$PASSWD\r"}
"Last login:" {send "\r"}
}
send "\r"
expect "#" {send "ifconfig | grep $IP\r"}
expect "$IP" {send "\r"}
expect "#" {send "cd $FTP_ROOT\r"}
expect "#" {send "dos2unix -q clean_env.sh\r"}
expect "#" {send "chmod 755 clean_env.sh\r"}
expect "#" {send "./clean_env.sh $LOCAL_TYPE\r"}
expect "#" {send "vgremove xxx\r"}
expect {
"\[y/n\]" {send "y\r"; exp_continue}
"#" {send "\r"}
}
send "\r"
send "exit\r"
expect eof
如上脚本,调用命令为:
./clean_env.exp FTP /root/Install_Tool 192.168.4.2 CLEAN_ENV xxxx xxxx
其中,vgremove的效果是:
image-001:~ # vgremove xxxx
Do you really want to remove volume group "xxxx" containing 1 logical volumes? [y/n]:
expect "#" {send "vgremove xxx\r"}
expect {
"\[y/n\]" {send "y\r"; exp_continue}
"#" {send "\r"}
}
期望中,vgremove应该会正常交互,但实际上,输出了一大堆的:
……
image-001:~/Install_Tool # y
If 'y' is not a typo you can run the following command to lookup the package that contains the binary:
command-not-found y
-bash: y: command not found
image-001:~/Install_Tool # y
If 'y' is not a typo you can run the following command to lookup the package that contains the binary:
command-not-found y
-bash: y: command not found
image-001:~/Install_Tool # e
If 'e' is not a typo you can run the following command to lookup the package that contains the binary:
image-001:~/Install_Tool #
并且脚本卡死,直到到达超时时间才退出。
百思不得其解,请教各位大牛,是原因导致这个问题?