加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

双层跳板机登陆服务器-shell脚本实现自动登陆

发布时间:2020-12-15 21:12:35 所属栏目:安全 来源:网络整理
导读:# !/usr/bin/expect # ## 两层跳板机版本 ### set timeout 15 set jumpusr [lindex $argv 0]set jumphost [lindex $argv 1 ]set jumppassword [lindex $argv 2 ]set usr [lindex $argv 3 ]set host [lindex $argv 4 ]set port [lindex $argv 5 ]set password
#!/usr/bin/expect

### 两层跳板机版本 ###

set timeout 15
set jumpusr [lindex $argv 0]
set jumphost [lindex $argv 1]
set jumppassword [lindex $argv 2]
set usr [lindex $argv 3]
set host [lindex $argv 4]
set port [lindex $argv 5]
set password [lindex $argv 6]
set server [lindex $argv 7]

# ssh 跳板机 输入账户名 密码
catch {spawn ssh [email?protected]$jumphost}
expect "*assword:*" {send "$jumppasswordr"}

# 选择跳板机
expect "Select server:*" {send "$serverr"}

# ssh 目标机器 输入账户名 密码
expect "*$jumphost*" { send "ssh -p $port [email?protected]$hostr" }
expect "*assword:*" {send "$passwordr"}

# 保持交互状态,并把控制权交给控制台
expect "*$host*"; interact

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读