+ -
当前位置:首页 → 问答吧 → expect解决passwd问题中,expect eof语句的理解

expect解决passwd问题中,expect eof语句的理解

时间:2011-02-23

来源:互联网

    spawn passwd test
    expect "*password:"  
    send "123456\r"  
    expect "*password:"  
    send "123456\r"  
    expect eof  


如果没有最后的expect eof语句,则不能正确执行,那这条语句应该怎么理解?

作者: zcsgamer   发布时间: 2011-02-23

本帖最后由 chinaboywg 于 2011-02-23 22:25 编辑

#!/usr/bin/expect
if {$argc!=2} {
send_user "Usage: $argv0 {ip} {passwd}\n"
exit
}
set ip [lindex $argv 0]
set passwd [lindex $argv 1]
spawn ssh root@$ip
expect "yes/no"
send "yes\r"
expect "*Password:*"
exec sleep 2
send -- "$passwd\r"
expect "*Permission denied*"
#send_user "password error"
expect "#"
send "uname -r\r"
expect "#"
exec sleep 5
send "exit\r"
expect eof

作者: chinaboywg   发布时间: 2011-02-23

同问

作者: kelehaier   发布时间: 2011-02-23

热门下载

更多