Mac-fastssh快速登跳转机

公司一个大牛的

复制代码
#!/usr/bin/expect
set timeout 20
set dest [lindex $argv 0]

# login jump3
spawn ssh wenbronk@sss.oss.le.cn -p 502
expect {
    "Connection refused" exit
    "Name or service not known" exit
    "continue connecting" {send "yes\r";exp_continue}
    "password:" {send "password\r"}
    "Last login" {send_user "login jump successful"}
}

if { $dest == "hive" } {
    set user "bronkwen"
    set ip "10.112.32.15"
    set password "b0GBH28"
} elseif { $dest == "rdp" } {
    set user "rdp"
    set ip "10.183.93.1"
} elseif { $dest == "asdf" } {
    set user "root"
    set ip "10.185.29.2"
    set password "SJevL6"
} elseif { $dest == "redis" } {
    set user "rot"
    set ip "10.1.96.87"
    set password "E3vQC92"
} elseif { $dest == "rdp_h" } {
    set user "bronkwen"
    set ip "10.183.3.1"
    set password "b28"
} elseif { $dest == "storm" } {
    set user "slog"
    set ip "10.110.155.8"
    set password ".com"
} else {
   interact
   exit
}

expect "*:h<Enter>*"
send ":"
expect "*:*"
send_user "login $ip by user:$user\n"
send "ssh $user@$ip\r"
expect {
    "Connection refused" exit
    "Name or service not known" exit
    "continue connecting" {send "yes\r";exp_continue}
    "password:" {send "$password\r"}
    "Last login" {send_user "login $ip by user:$user\n successful"}
}

set rdp_ip [lindex $argv 1]
if { $dest != "rdp" || $rdp_ip == "" } {
   interact
   exit
}

if { $rdp_ip == "mongo" } {
    set rdp_ip "10.183.6.193"
} elseif { $rdp_ip == "canal1" } {
    set rdp_ip "10.110.1.35"
} elseif { $rdp_ip == "canal2" } {
    set rdp_ip "10.110.1.36"
}

send "ssh root@$rdp_ip\r"
expect {
    "Connection refused" exit
    "Name or service not known" exit
    "continue connecting" {send "yes\r";exp_continue}
    "Last login" {send_user "login $ip by user:$user\n successful"}
}
interact
复制代码

 

精简了下, 用来登陆我的虚拟机

复制代码
#!/usr/bin/expect                                                                                                                                                                                               
set timeout 20
set dest [lindex $argv 0]

set user "root"
set password "root"

if { $dest == "node1" } {
    set ip "192.168.199.115"
} elseif { $dest == "rdp" } {
    set ip "192.168.199.176"
} elseif { $dest == "asdf" } {
    set ip "192.168.199.189"
} elseif { $dest == "redis" } {
    set ip "192.168.199.181"
} else {
   echo unkonw server
   interact
   exit
}

spawn ssh $user@$ip -p 22
expect {
    "Connection refused" exit
    "Name or service not known" exit
    "password" {send "$password\r" }
    "continue connecting" {send "yes\r";exp_continue}
    "Last login" {send_user "login $ip by user:$user\n successful"}
}
interact
复制代码

 

把文件命令为  fastss, 放在  ~/soft/path/fastssh, 然后修改  /etc/profile, 增加环境变量

之后就可以在任意地方使用   `fastssh node1`  的方式来登录了

 

posted @   bronk  阅读(144)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示