我怎样才能简化这个期望的脚本?

我做了一个脚本来改变许多服务器的密码。 它的语法是期望的 – tcl的扩展。 这似乎很糟糕,但可以正常工作。

一个问题是当我第一次login服务器时,我需要input'yes'来确认添加这个服务器到〜/ .ssh / know_hosts。 很久没有我了 有没有简单的风格来解决这个问题?

谢谢你,对我可怕的英语感到抱歉。

proc passwd4mqm {ip_list} { foreach Arg $ip_list { set city [lindex $Arg 0] set ip [lindex $Arg 1] set user [lindex $Arg 2] set passwd [lindex $Arg 3] send_user "\n\n>>> $city-$ip \n" spawn ssh $user@$ip expect { "yes" { send "yes\r" expect { "password" { send "$passwd\r" expect { "$user" { send "passwd mqm\r" expect { "New UNIX password:" { send "$passwd\r" expect { "Retype new UNIX password:" { send "$passwd\r"} } } } send "exit\r" } } } } } "password" { send "$passwd\r" expect { "$user" { send "passwd mqm\r" expect { "New UNIX password:" { send "$passwd\r" expect { "Retype new UNIX password:" { send "$passwd\r"} } } } send "exit\r" } } } } interact } } 

也许你正在寻找像exp_continue类的exp_continue

 expect { "*yes/no*" { send "yes\r"; exp_continue } "password:" { ..... } }