请即兴发布此代码,谢谢。 我有以下登录脚本,允许用户 1)然后进入服务器 2)然后登录env(QA或DEV或PROD) 3)使用" suuser" - 从用户输入,最后允许用户登录到App主机。 在我的期望脚本中,最后两行代码使用$ suuser登录App主机,我想允许用户尝试5次,如果不成功,我仍然希望继续当前会话,因为当前用户在第二步登录到环境
expect -c '
puts -nonewline "please enter a swithch user: "
flush stdout
set suuser [gets stdin]
set userAcc "$env(unixID)";
set userPass "$env(unixPass)";
puts "'$1' '$2'";
spawn ssh $userAcc@'$1'
expect {
"(yes/no)? " {
send "yes\r"
expect "*assword:*" { send "$userPass\r" }
}
"*assword:*" { send "$userPass\r" }
}
expect "*bash*" { send "ssh $userAcc@'$2'\r" }
expect {
"(yes/no)? " {
send "yes\r"
expect "*assword:*" { send "$userPass\r" }
set count 5;
while {$count > 0 } {
puts "count : $count\n";
if { [string compare $suuser ""] == 0 } {
puts -nonewline "please enter a swithch user: "
flush stdout
set suuser [gets stdin]
puts $suuser
}
set count [expr $count-1];
}
expect -re "*bash*" { send "sudo -u $suuser -i\r" }
#expect "*$suuser*" {send "$userPass\r" }
}
}
interact
'