背景
shell快速登录多个机器。
平时需要经常切换多个机器,或者需要通过跳板机来回换登录机器。
为了便于自己快速登录,和每次找机器,写了登录管理工具https://github.com/cgpeter96/shell/blob/main/login_remote.sh。
依赖
基于expect和shell编写,因此需要安装expect
#rehat or centos
yum install expect
# debian
apt install expect
脚本说明
每次有新机器的时候就复制下以下内容 然后保存登录就行了。
host_list[${#host_list[@]}]="xxx.xx.com"
username_list[${#username_list[@]}]="username"
password_list[${#password_list[@]}]="password"
port_list[${#port_list[@]}]="22"
msg_list[${#msg_list[@]}]="测试机"
使用
bash login_remote.sh
结论
妙蛙种子来了米奇妙妙屋。