JumpServer
编写shell程序,在跳板机上连接N台服务器
#!/bin/bash
#name:katixiya
#time:2025.10.17
web=IP地址
mysql=IP地址
nginx=IP地址
............
#打印跳转菜单
show_menu () { #创建主机菜单函数
cat <<-EOF
1.web
2.mysql
3.nginx
............
4.help
5.exit
EOF
}
show_menu
read -p "please input host number:[help 4]" num
case $num in
1)
ssh root@$web
;;
2)
ssh root@mysql
;;
3)
ssh root@nginx
;;
4)
show_menu
;;
5)
exit 88
;;
esac
ping测试主机在线
#!/bin/bash
#name:katixiya
#time:2025.10.17
>ip.txt #清空文本
for i in {2..254}
do
{
ip=155.155.155.$i #网段
ping -c1 -W1 $ip &> /dev/null
if [ $? -eq 0 ];then
echo "$ip" |tee -a ip.txt
fi
}& #后台执行
done
wait #等待前一个执行完后再执行下一个
echo "finish..."