expect實現自動登陸

自動登陸主機(ssh)bash

建腳本item2login.sh,包含以下內容ssh

#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
	"*(yes/no)?" {
            send "yes\n"
            expect "assword:"
	    send "[lindex $argv 3]\n"
	}
	"*assword:" {
            send "[lindex $argv 3]\n"
        }
}
interact

  

使用方法: item2login.sh port user host passwordspa

如:blog

item2login.sh 22 dev 127.0.0.1 123456 it

ssh 登陸端口 22class

登陸用戶名 dev登錄

登陸的主機 127.0.0.1密碼

登陸密碼 123456方法

相關文章
相關標籤/搜索