expect 示例

#!/usr/bin/expect
set timeout 30
set IP [lindex $argv 0]
set USER [lindex $argv 1]
spawn ssh $USER@$IP
expect {
"Are you sure you want to continue connecting (yes/no)?" {
send "yes "
expect -re "[P|p]assword:" {send "123 "}
}
-re "[P|p]assword:" {send "123 "}
}
expect "~]" {send "touch /tmp/eeee "}
expect "~]" {send "uname -r "}
expect eof

 执行脚本 ./test.sh "192.168.0.105" root

原文地址:https://www.cnblogs.com/jkklearn/p/10372036.html