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

posted on 2019-02-13 21:58  思此狂  阅读(126)  评论(0编辑  收藏  举报

导航