JumperServer跳板机登录

Summary: Author: 张亚飞 | Read Time: 1 minute read | Published: 2020-04-22
Filed under Categories: LinuxTags: SSH,

JumperServer跳板机登录

需要安装 expect 程序

brew install expect

常用命令有以下:

  • send:用于向进程发送字符串
  • send_user:向当前用户打印消息
  • expect:从进程接收字符串, 即必须接手spawn进程的命令
  • exp_continue:循环继续进行
  • spawn:启动新的进程
  • interact:允许用户交互
#!/bin/bash

search=$1

user=zhangyafei
password=******
send_cmd=$search

cmd=$(cat <<EOF
spawn ssh $user@jumpserver.coam.com -p 22312
expect {
    "*password*" {
        send "$password\r"
        exp_continue
    }
    "*Opt*" {
        send "$send_cmd\r"
    }
}
interact
EOF)

expect -c "$cmd"

Comments

Cor-Ethan, the beverage → www.iirii.com