mac使用expect实现自动登录跳板机

之前一直手动输入密码来登录跳板机,换了新公司要跳两次很麻烦  网上看到了expect很好用  记录下


  1. mac上安装expect 和 ga-cmd
  2. 使用expect实现自动登录的自行优化脚本如下
    1. #这个是expect交互的脚本,支持输入参数
      #!/usr/bin/expect -f
       
      #设置超时时间
       
      set  timeout 3
       
      #通过参数传递 这里拿到token
       
      set  verification [lindex $argv 0]
       
      #私人密码
       
      set  password yourpassword
       
      # 连接跳板机
       
      set  host [lindex $argv 1]
       
      spawn  ssh  $host -p35000
       
      #选择中控机的数字
      set  num [lindex $argv 2]
       
      #如果返回的内容包含*Verification code*,发送动态token值
       
      expect  "*Verification code*"  {send  "$verification\n" }
       
      #如果返回的内容包含"*password*",发送你设置的密码+\n 下面的两个类似
       
      expect  "*Password*"  {send  "$password\n" }
       
      expect  "*Option*"  {send  "$num\n" }
      #保持在远端  
      interact
    2. 对于动态token的生成 通过ga-cmd来获得

ga-cmd安装:http://blog.csdn.net/xingeryue1990/article/details/52980447

猜你喜欢

转载自blog.csdn.net/weiguang111/article/details/78595145