Bash foreach循环中expect异常处理的问题
我有一个expect脚本,可以在远程设备上启动命令,有些设备可能存在凭据问题,如果输入密码后重复密码提示,我需要跳过这些问题Bash foreach循环中expect异常处理的问题,bash,tcl,expect,Bash,Tcl,Expect,我有一个expect脚本,可以在远程设备上启动命令,有些设备可能存在凭据问题,如果输入密码后重复密码提示,我需要跳过这些问题 #!/usr/bin/expect -f set x [list 192.168.1.1 192.168.1.2] foreach hosts $x { # spawn ssh sy-nep-oss@$x sleep 5 spawn ssh -o StrictHostKeyChecking=no sy
#!/usr/bin/expect -f
set x [list 192.168.1.1 192.168.1.2]
foreach hosts $x {
# spawn ssh sy-nep-oss@$x
sleep 5
spawn ssh -o StrictHostKeyChecking=no sy-nep-oss@$hosts
sleep 5
**expect {"password: "
send -- "abcd\r"
expect "*>"
如果密码不正确,则需要跳过此循环迭代并转到列表中的下一项
send -- "cd cfcard:/ \r"
sleep 2
expect "*>"
send -- "cd cfcard2:/ \r"
sleep 2
expect "*>"
sleep 2
send -- "dir log* \r"
expect "*>"
sleep 2
send "cd log \r"
expect {enter code here
"Error: Wrong path *" {
send "cd logfile \r"
}
"logfile*" {
send "cd log \r"
}
}
expect "*>"
sleep 2
send -- "dir log.log \r"
expect "*>"
sleep 2
send -- "system-view \r"
expect "Enter system view*"
sleep 2
send -- "sftp 212.72.10.182 \r"
expect "*username*"
sleep 2
send -- "test\r"
expect "*password:"
sleep 2
send -- "Y\r"
sleep 3
send -- "N \r"
sleep 4
expect "Please select public key type for user authentication*"
send -- "R \r"
sleep 2
expect "*password"
sleep 2
expect "sftp-client>"
sleep 2
send -- "put log.log $hosts.log \r "
sleep 2
expect "sftp-client>"
sleep 2
send -- "quit\r"
sleep 2
send -- "quit\r"
sleep 2
send -- "quit\r"
}
expect eof
你的问题是什么?要求是如果密码登录失败,即提示passwrd repeats我需要掌握以下命令并转到arrayTcl中的下一项。当你说“skill”时,你可能是指“skip”?是的,很抱歉输入错误,例如跳过错误的IP地址,您有一个您没有权限的设备,因此请转到下一个!