expect

#!/usr/bin/expect -f
set ipaddr "192.168.5.4"
set passwd "123qwe"
set timeout 30

spawn ssh root@$ipaddr
expect {
"yes/no" { send "yes\r"; exp_continue }
"password: " { send "$passwd\r" }
}
expect "*# "
send "ls\r"
send "exit\r"
expect eof
exit

posted @ 2016-07-17 10:08  若丶相依  阅读(169)  评论(0编辑  收藏  举报