ssh自动登入脚本

#!/usr/bin/expect -f

if { $argc < 3 } {
puts stderr "Usage: $argv0 IPAdress Login OldPasswd"
exit
}

set IPADDR [lindex $argv 0]
set LOGIN [lindex $argv 1]
set OLD_PW [lindex $argv 2]

set timeout -1 

#stty -echo

spawn ssh $IPADDR -l $LOGIN
expect {
    "*assword:*"  {
        send "$OLD_PW\r"
        exp_continue
    } "*ast login:*" {
        interact
        exit 0
    } timeout {
        send_user "connection to $IPADDR timeout!\n"
        exit 1
    } "*incorrect*" {
        send_user "password incorrect!\n"
        exit 2
    } "*ermission*" {  #for LINUX ssh
        send_user "password Error!\n"
        exp_continue
        exit 2
    } eof {
        exit 3
    }
}

使用方法 : ./my_ssh.sh192.168.156.10 root 123456

标签:Linux, Shell

评论已关闭