脚本

# 跳板机
```bash
#自动切换终端脚本,脚本不认识别名(ll),判断里面不能接 >/dev/null,不然会夯住
vim QH.sh
#脚本1
#!/bin/bash
cat <<EOF
+------------+
|1.连接web01 |
+------------+
|2.连接web02 |
+------------+
|3.连接nfs   |
+------------+
|4.连接backup|
+------------+
EOF
read -p '请输入想要连接的虚拟机的序号:' num

if    [ $num -eq 1 ];then
	ssh root@172.16.1.7
elif  [ $num -eq 2 ];then
	ssh root@172.16.1.8 
elif  [ $num -eq 3 ];then
 	ssh root@172.16.1.31 
elif  [ $num -eq 4 ];then
	ssh root@172.16.1.41 
fi

# if    [ $num -eq 1 -o $num == web01 ];then	不能这样写

#脚本2
#!/bin/bash
cat <<EOF
+------------+
|1.连接web01 |
+------------+
|2.连接web02 |
+------------+
|3.连接nfs   |
+------------+
|4.连接backup|
+------------+
EOF
read -n1 -p "请输入想要连接的虚拟机的序号: " answer
case $answer in
1)
      ssh root@172.16.1.7;;
2)
      ssh root@172.16.1.8;;
3)
      ssh root@172.16.1.31;;
4)
      ssh root@172.16.1.41;;
esac
exit 0

#脚本3
vim jumpserver.sh
#!/bin/bash
#jumpserver
lb01=172.16.1.5
lb02=172.16.1.6
web01=172.16.1.7
web02=172.16.1.8
web03=172.16.1.9
nfs=172.16.1.31
backup=172.16.1.41
db01=172.16.1.51
db02=172.16.1.52
db03=172.16.1.53
db04=172.16.1.54
m01=172.16.1.61
zabbix=172.16.1.71

cat <<EOF
        +-------------------------+
        |     1) lb01             |
        |     2) lb02             |
        |     3) web01            |
        |     4) web02            |
        |     5) web03            |
        |     6) nfs              |
        |     7) backup           |
        |     8) db01             |
        |     9) db02             |
        |     10) db03            |
        |     11) db04            |
        |     12) m01             |
        |     13) zabbix          |
        |     h) help             |
        +-------------------------+
EOF
read -p 'Please Input Number: ' num

if [ $num -eq 1 ];then
  ssh root@$lb01
elif [ $num -eq 2 ];then
  ssh root@$lb02
elif [ $num -eq 3 ];then
  ssh root@$web01
elif [ $num -eq 4 ];then
  ssh root@$web02
elif [ $num -eq 5 ];then
  ssh root@$web03
elif [ $num -eq 6 ];then
  ssh root@$nfs
elif [ $num -eq 7 ];then
  ssh root@$backup
elif [ $num -eq 8 ];then
  ssh root@$db01
elif [ $num -eq 9 ];then
  ssh root@$db02
elif [ $num -eq 10 ];then
  ssh root@$db03
elif [ $num -eq 11 ];then
  ssh root@$db04
elif [ $num -eq 12 ];then
  ssh root@$m01
elif [ $num -eq 13 ];then
  ssh root@$zabbix
fi
posted @ 2020-05-13 17:39  看萝卜在飘  阅读(205)  评论(0编辑  收藏  举报