expect 使用

参考:http://www.cnblogs.com/iloveyoucc/archive/2012/05/11/2496433.html

 

 

自己的小例子:

  1. ssh 到堡垒机
  2. 选择跳转服务器
  3. ssh 到目标服务器
  4. cd 到目录

login_ssh.exp

 1 #!/usr/bin/expect
 2 set timeout 30
 3 spawn ssh  xxx@xxx
 4 expect "Password:"
 5 send "xxx\r"
 6 expect "Select server:"
 7 send "x\r"
 8 expect -re ".*xxx.*"
 9 spawn ssh xxx@xxx
10 expect -re ".*password:"
11 send "xxx\r"
12 expect -re ".*xxx.*"
13 send "cd /xxx\r"
14 interact

 

posted @ 2016-11-11 17:25  jellyabd  阅读(174)  评论(0编辑  收藏  举报