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\r"
expect -re "\[P|p]assword:" {send "123\r"}
}
-re "\[P|p]assword:" {send "123\r"}
}
expect "~]" {send "touch /tmp/eeee\r"}
expect "~]" {send "uname -r\r"}
expect eof
执行脚本 ./test.sh "192.168.0.105" root