首页 > 其他 > 详细

1.8-自动登陆后执行命令

时间:2016-03-09 07:07:15      阅读:286      评论:0      收藏:0      [点我收藏+]

再来看一个登陆后,执行命令然后退出的脚本:


#!/usr/bin/expect

set user "root"

set passwd "123456"

spawn ssh $user@192.168.11.18

expect {

"yes/no" { send "yes\r"; exp_continue}

"password:" { send "$passwd\r" }

}                                      #以上和上一个脚本相同

expect "]*"                            

send "touch /tmp/12.txt\r"

expect "]*"

send "echo 1212 > /tmp/12.txt\r"

expect "]*"

send "exit\r"


注意:登陆远程机器后,命令行为[root@wyp ~]#  所以expect "]*"的意思是匹配"]"和*(任意一个字符),因为有的机器是#有的也可能是$或者其他。


1.8-自动登陆后执行命令

原文:http://llzdwyp.blog.51cto.com/6140981/1748928

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!