码迷,mamicode.com
首页 > 系统相关 > 详细

〖Linux〗bash和expect执行ssh命令行sshcmd.exp

时间:2014-10-16 16:20:22      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   使用   ar   sp   div   log   

 1 #!/usr/bin/expect -f
 2 # sudo apt-get install expect
 3 # ./ssh.exp user passwd server
 4 set user [lrange $argv 0 0]
 5 set pass [lrange $argv 1 1]
 6 set server [lrange $argv 2 2]
 7 set cmds [lrange $argv 3 $argc]
 8 
 9 spawn ssh -o StrictHostKeyChecking=no $user@$server $cmds
10 match_max 100000
11 expect "*?assword:*"
12 send -- "$pass\r"
13 send -- "\r"
14 interact

使用举例:

  sshcmd.exp user passwd 192.168.1.100 ls -l /

〖Linux〗bash和expect执行ssh命令行sshcmd.exp

标签:style   blog   color   os   使用   ar   sp   div   log   

原文地址:http://www.cnblogs.com/scue/p/4028735.html

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