#! /usr/bin/expect
set IP [lindex $argv 0]
set PWD [lindex $argv 1]
spawn ssh root@$IP
expect {
"*(yes/no)?*" {
send "yes\r"
expect "*password:*"
send "$PWD\r"
}
"*password:*" {
send "$PWD\r"
}
}
interact
存储上述代码为auto_ssh.sh,
chmod +x auto_ssh.sh
使用方法
./auto_ssh.sh ip password