ssh 登录管理工具
- ssh登录管理工具脚本
#!/bin/bash
#Author:weidada
#Version:1.0
#CreateTime:2020-08-25 10:09:03
#--------Description------------
# 需要提前安装expect
#--------Description------------
host_list=(
#"编号\t|自定义名称\t|IP地址"
"1\t|测试服务器1\t|192.168.1.1"
)
host_str=(
#"ssh登录用户@IP"
"test-user@192.168.1.1"
)
pwd_list=(
#密码
"test123"
)
showlist(){
echo -e "ID\t主机名\t\t\tip"
echo "----------------------------------------------"
for host in ${host_list[@]};
do
echo -e $host
done
echo "请输入选择要登录的主机的ID(输入exit退出):"
}
checkHost(){
read key
if [[ $key == 'exit' ]]; then
exit
fi
login_host=${host_str[$key]}
login_pwd=${pwd_list[$key]}
}
checkParams(){
if [[ ! $login_host ]] || [[ ! $login_pwd ]]; then
echo '----------不存在的主机-------------';
echo "请输入选择要登录的主机的ID(输入exit退出):"
whileList
fi
}
autoSsh(){
expect -c "
spawn ssh $login_host
expect {
\"yes\/no\" { send \"yes\n\"; exp_continue}
\"password:\" { send \"$login_pwd\n\" }
}
interact
"
}
whileList(){
checkHost
checkParams
}
main(){
whileList
autoSsh
}
showlist
main
- 赋给执行权限
chmod 600 auto-ssh-login.sh
chmod +x auto-ssh-login.sh
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。