shell脚本自动登录远程主机执行脚本或命令

#!/usr/bin/expect
set WORK_PATH "/root"
set hostname "10.239.227.224"
spawn  ssh root@$hostname
expect  {
"yes/no"
{send "yes\r";}
#{send "yes\r"; exp_continue;}
"password:"
{exp_send  "123456\r";}
"password:"
{exp_send  "123456\r";}
         }


puts "\n*****************************************************************************************************"
puts "\n                 LOGIN ${hostname} SUCCESSFULLY  START TO EXCUTE COMMAND       "
puts "\n*****************************************************************************************************"

expect "root@*"  {send "cd ${WORK_PATH}\r"}
expect "root@*"  {send "sh usbrelay.sh allon\r"}
expect "root@*"  {send "exit\r"}
 

你可能感兴趣的:(Linux)