expect

yum install expect
#!/usr/bin/expect

set timeout 5

password=ppp

spawn ssh user@localhost -p 22
expect {
    "(yes/no)" { send "yes\r"; exp_continue }
    "password:" { send "$password\r" }
}
expect user@*   {send \" ls -l \r\" }  ;
expect user@*  { send exit\r } ;
expect 100% ;
expect eof ;

猜你喜欢

转载自ssydxa219.iteye.com/blog/2417277