码迷,mamicode.com
首页 > 其他好文 > 详细

命令远程连接ssh并执行命令

时间:2017-12-04 23:32:30      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:nbsp   环境   usr   eof   expec   pass   才有   dha   连接   

环境: redhat 6.5

网上测试了很多写法都不成功,测试了很久才有了一下脚本。

命令远程连接ssh并执行命令,scp/ftp等远程连接操作同理

#!/usr/bin/expect

set passwd "password"

set user "root"

set host "192.168.1.168"

spawn ssh $user@$host

#expect "yes/no"

#send "yes\r"  

expect  "password"

send "$passwd\r"

expect "$user@"

send "echo ‘passwd‘ >> /root/for_test.sh\r"

expect "$user@"

send "exit\r"

expect eof

命令远程连接ssh并执行命令

标签:nbsp   环境   usr   eof   expec   pass   才有   dha   连接   

原文地址:http://www.cnblogs.com/manug/p/7979277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!