当前位置:网站首页>Shell case: jumpserver jumper
Shell case: jumpserver jumper
2022-08-05 20:22:00 【AHui_CSDN】
ssh连接框架:
[[email protected] day5]# cat jumpserver.sh
#!/bin/bash
WEB01=172.16.1.7
WEB02=172.16.1.8
NFS=172.16.1.31
BACKUP=172.16.1.41
DB01=172.16.1.51
LB01=172.16.1.5
LB06=172.16.1.6
echo -e "\t\t\t\t\t\t 1.WEB01"
echo -e "\t\t\t\t\t\t 2.WEB02"
echo -e "\t\t\t\t\t\t 3.NFS"
echo -e "\t\t\t\t\t\t 4.BACKUP"
echo -e "\t\t\t\t\t\t 5.DB01"
read -p "Please enter the number of the host you want to log into: " num
case $num in
1|web01)
ssh $WEB01
;;
2)
ssh $WEB02
;;
3)
ssh $NFS
;;
*)
echo "Usage: $0 [1|2|3|4]"
esac
运维代码:
[[email protected] day5]# cat jumpserver.sh
#!/bin/bash
WEB01=172.16.1.7
WEB02=172.16.1.8
NFS=172.16.1.31
BACKUP=172.16.1.41
DB01=172.16.1.51
LB01=172.16.1.5
LB06=172.16.1.6
kf(){
echo -e "\t\t\t\t\t\t 1.WEB01=172.16.1.7"
}
yw(){
echo -e "\t\t\t\t\t\t 1.WEB01=172.16.1.7"
echo -e "\t\t\t\t\t\t 2.WEB02=172.16.1.8"
echo -e "\t\t\t\t\t\t 3.NFS=172.16.1.31"
echo -e "\t\t\t\t\t\t 4.BACKUP=172.16.1.41"
echo -e "\t\t\t\t\t\t 5.DB01=172.16.1.51"
echo -e "\t\t\t\t\t\t h.显示菜单"
}
echo -e "\t\t\t\t\t\t 1.运维"
echo -e "\t\t\t\t\t\t 2.开发"
read -p "请选择你的身份: " num
if [ $num -eq 1 ];then
yw
while true
do
read -p "Please enter the number of the host you want to log into[h显示菜单]: " num
case $num in
1|web01)
ssh $WEB01
;;
2)
ssh $WEB02
;;
3)
ssh $NFS
;;
h)
clear
yw
;;
*)
echo "Usage: $0 [1|2|3|4]"
esac
done
fi
开发代码:
[[email protected] day5]# cat jumpserver.sh
#!/bin/bash
WEB01=172.16.1.7
WEB02=172.16.1.8
NFS=172.16.1.31
BACKUP=172.16.1.41
DB01=172.16.1.51
LB01=172.16.1.5
LB06=172.16.1.6
kf(){
echo -e "\t\t\t\t\t\t 1.WEB01=172.16.1.7"
}
yw(){
echo -e "\t\t\t\t\t\t 1.WEB01=172.16.1.7"
echo -e "\t\t\t\t\t\t 2.WEB02=172.16.1.8"
echo -e "\t\t\t\t\t\t 3.NFS=172.16.1.31"
echo -e "\t\t\t\t\t\t 4.BACKUP=172.16.1.41"
echo -e "\t\t\t\t\t\t 5.DB01=172.16.1.51"
echo -e "\t\t\t\t\t\t h.显示菜单"
}
echo -e "\t\t\t\t\t\t 1.运维"
echo -e "\t\t\t\t\t\t 2.开发"
read -p "请选择你的身份: " num
if [ $num -eq 1 ];then
yw
while true
do
read -p "Please enter the number of the host you want to log into[h显示菜单]: " num
case $num in
1|web01)
ssh $WEB01
;;
2)
ssh $WEB02
;;
3)
ssh $NFS
;;
h)
clear
yw
;;
*)
echo "Usage: $0 [1|2|3|4]"
esac
done
elif [ $num -eq 2 ];then
kf
while true
do
read -p "Please enter the number of the host you want to log into[h显示菜单]: " num
case $num in
1|web01)
ssh $WEB01
;;
2)
ssh $WEB02
;;
3)
ssh $NFS
;;
h)
clear
kf
;;
*)
echo "Usage: $0 [1|2|3|4]"
esac
done
fi
完善脚本:
[[email protected] day5]# cat jumpserver.sh
#!/bin/bash
WEB01=172.16.1.7
WEB02=172.16.1.8
NFS=172.16.1.31
BACKUP=172.16.1.41
DB01=172.16.1.51
LB01=172.16.1.5
LB06=172.16.1.6
kf(){
echo -e "\t\t\t\t\t\t 1.WEB01=172.16.1.7"
}
yw(){
echo -e "\t\t\t\t\t\t 1.WEB01=172.16.1.7"
echo -e "\t\t\t\t\t\t 2.WEB02=172.16.1.8"
echo -e "\t\t\t\t\t\t 3.NFS=172.16.1.31"
echo -e "\t\t\t\t\t\t 4.BACKUP=172.16.1.41"
echo -e "\t\t\t\t\t\t 5.DB01=172.16.1.51"
echo -e "\t\t\t\t\t\t h.显示菜单"
echo -e "\t\t\t\t\t\t 6|q.返回主菜单"
}
menu(){
echo -e "\t\t\t\t\t\t 1.运维"
echo -e "\t\t\t\t\t\t 2.开发"
echo -e "\t\t\t\t\t\t 3|g.娱乐一下"
}
trap "echo Don't press and be careful to explode" INT HUP TSTP
while true
do
menu
read -p "请选择你的身份: " num
if [ $num -eq 1 ];then
while true
do
read -s -p "Enter the operation and maintenance password: " pass
if [ $pass = oldboy123 ];then
echo "Welcome home"
yw
while true
do
read -p "Please enter the number of the host you want to log into[h显示菜单]: " num
case $num in
1|web01)
ssh $WEB01
;;
2)
ssh $WEB02
;;
3)
ssh $NFS
;;
h)
clear
yw
;;
6|q)
break 2
;;
woshiyunwei)
exit
;;
*)
continue
esac
done
else
let i++
if [ $i -eq 3 ];then
echo "think about typing"
sleep 2
continue
fi
echo "Enter the wrong password and re-enter it"
continue
fi
done
elif [ $num -eq 2 ];then
kf
while true
do
read -p "Please enter the number of the host you want to log into[h显示菜单]: " num
case $num in
1|web01)
ssh $WEB01
;;
2)
ssh $WEB02
;;
3)
ssh $NFS
;;
h)
clear
kf
;;
woshiyunwei)
exit
;;
*)
echo "Usage: $0 [1|2|3|4]"
esac
done
elif [ $num -eq 3 ];then
sh game.sh
fi
done
expectSend keys without interaction
[[email protected] day5]# cat test.ex
#!/usr/bin/expect
set timeout 10
set user root
set ip 172.16.1.31
set password 1
spawn ssh-copy-id $user@$ip
expect {
"yes/no" {
send "yes\n";exp_continue }
"password" {
send "$password\n" }
}
interact
边栏推荐
猜你喜欢
随机推荐
两数、三数之和
IPv4和IPv6有什么区别
【Harmony OS】【FAQ】鸿蒙问题合集2
RAID磁盘阵列详解
第十五天(下)安装newman与jenkins使用
Rust学习笔记:1.2 两个典例及常用命令
【idea插件】MetricsReloaded使用
【ML】机器学习数据集:sklearn中回归数据集介绍
软考 --- 软件工程(3)软件测试
D碳社区推荐读物:《碳中和与中国未来》:从大国博弈角度解读碳中和
Shell(5)数组
报告分享|2022年深度学习平台发展报告PPT
3D U-Net: Learning Dense Volumetric Segmentation from Sparse Annotation
如何进行技术面试?
SwiftUI案例:自定义加载动画
开发之JS|通过原生来实现一个简单的拦截器功能
App测试时常用的adb命令你都掌握了哪些呢?
vi学习(1)【简介/基本使用/工作模式】
方舟生存进化下载服务器文件及搜服方法
SwiftUI case: Lottie loading animation









