linux通过expect远程登录并执行命令

#!/usr/bin/expect
set timeout 60
set username root
set password 88888888
set hostname syd

spawn ssh $username@$hostname
expect {
"yes/no"
{send "yes\r"; exp_continue;}
"password:"
{send "$password\r";}
}
expect -re "root@Sunyard" {send "touch test.txt\r"}
expect -re "root@Sunyard" {send "exit\r"}
exit

posted @ 2021-04-20 16:02  TIMLONG  阅读(368)  评论(0编辑  收藏  举报