歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Linux下Dialog+Shell三層目錄專業規范跳板機腳本

Linux下Dialog+Shell三層目錄專業規范跳板機腳本

日期:2017/3/3 11:42:06   编辑:SHELL編程
#Dialog+Shell介紹
Dialog+Shell結合使用,方能體現出Dialog圖形化的效果,在運維的時候,使用圖形化界面,能給你一個更直觀的感受,相信你會喜歡上他的


#創建腳本目錄
[root@localhost ~]# mkdir -p /scripts/tiaoban/{qqandroid,qqios,qqwxandroid,wxios,menu_list}

#禁止普通用戶登陸
[root@localhost ~]# cat /etc/profile.d/tiaoban.sh
[ $UID -ne 0 ] && sh /scripts/tiaoban/tiaoban.sh

#腳本目錄結構
[root@localhost tiaoban]# tree /scripts/tiaoban/
/scripts/tiaoban/
├── menu_list
│   ├── one_menu
│   └── one_option
├── qqandroid
│   ├── three_directory
│   │   ├── ip.txt
│   │   ├── three_1_100_tiaoban.sh
│   │   ├── three_menu
│   │   └── three_option
│   ├── tow_menu
│   ├── tow_option
│   └── tow_tiaoban.sh
├── qqios
├── qqwxandroid
├── tiaoban.sh
└── wxios
6 directories, 10 files

#添加權限
[root@localhost tiaoban]# chmod +x /scripts/tiaoban/menu_list/{one_menu,one_option}
[root@localhost tiaoban]# chmod +x /scripts/tiaoban/qqandroid/{tow_menu,tow_option}
[root@localhost tiaoban]# chmod +x /scripts/tiaoban/qqandroid/three_directory/{three_menu,three_option}

#第一層目錄腳本
[root@localhost tiaoban]# cat tiaoban.sh 
#!/bin/bash
while :
do
stty susp ^@#$  #屏蔽Crtl +z
stty intr ^@$#  #屏蔽Ctrl +c
stty quit ^*#$  #屏蔽Ctrl +l
LJ=`dirname $0` 
dialog --title "Menu" --no-cancel --menu "Level directory" 12 35 5 `cat $LJ/menu_list/one_menu` 2> $LJ/menu_list/one_option 
SELECT=`cat $LJ/menu_list/one_option`
if [ "$SELECT" == 1 ];then
        sh $LJ/qqandroid/tow_tiaoban.sh
elif [ "$SELECT" == 2 ];then
        sh $LJ/qqios/tow_tiaoban.sh
elif [ "$SELECT" == 3 ];then
        sh $LJ/wxandroid/tow_tiaoban.sh
else
        sh $LJ/wxios/tow_tiaoban.sh
fi
done

#第一層目錄菜單
[root@localhost tiaoban]# cat /scripts/tiaoban/menu_list/one_menu 
1 qqandroid 
2 qqios(功能未開發)
3 wxandroid(功能未開發)
4 wxios(功能未開發)

#第二層目錄腳本
[root@localhost tiaoban]# cat /scripts/tiaoban/qqandroid/tow_tiaoban.sh 
#!/bin/bash
while :
do
LJ=`dirname $0`
dialog --title "Menu" --menu "Secondary directory" 13 35 15 `cat $LJ/tow_menu` 2> $LJ/tow_option
SELECT=`cat $LJ/tow_option`
if [ "$SELECT" == 1 ];then
        sh $LJ/three_directory/three_1_100_tiaoban.sh
elif [ "$SELECT" == 2 ];then
        sh $LJ/three_directory/three_101_200_tiaoban.sh
elif [ "$SELECT" -eq 3 ];then
        sh $LJ/three_directory/three_201_300_tiaoban.sh
else 
        sh /scripts/tiaoban/tiaoban.sh
fi
done

#第二層目錄菜單
[root@localhost tiaoban]# cat /scripts/tiaoban/qqandroid/tow_menu 
1 qqandroid1-100服
2 qqandroid101-200服(功能未開發)
3 qqandroid201-300服(功能未開發)
4 返回上一級

#第三層目錄腳本
[root@localhost tiaoban]# cat /scripts/tiaoban/qqandroid/three_directory/three_1_100_tiaoban.sh 
#!/bin/bash
while :
do
LJ=`dirname $0`
dialog --title "Menu" --menu "Three directory" 13 35 15 `cat $LJ/three_menu` 2> $LJ/three_option
SELECT=`cat $LJ/three_option`
function connect() {
        yh=`id`
        user=`echo $yh | awk -F" " '{print $2}' | awk -F"gid=" '{print $2}' | awk -F"(" '{print $2}' | awk -F")" '{print $1}'`
        ip=`head -$SELECT $LJ/ip.txt | tail -1`
        ssh -p 22 $user@$ip
}
if [ "$SELECT" == 5 ];then
        sh /scripts/tiaoban/qqandroid/tow_tiaoban.sh
elif [ "$SELECT" == 6 ];then
        sh /scripts/tiaoban/tiaoban.sh  
else
        connect   
fi
done

第三層目錄菜單
[root@localhost tiaoban]# cat /scripts/tiaoban/qqandroid/three_directory/three_menu 
1 qq1服
2 qqandroid2服(功能未開發)
3 qqandroid3服(功能未開發)
4 qqandroid...服(功能未開發)
5 返回上一級目錄
6 返回首頁

#IP文件展示
[root@localhost tiaoban]# cat /scripts/tiaoban/qqandroid/three_directory/ip.txt 
192.168.1.103
192.168.1.104
192.168.1.105
192.168.1.106
192.168.1.107
192.168.1.108
192.168.1.109
192.168.1.110
192.168.1.111
192.168.1.112

#執行效果展示
1)普通用戶登陸



2)第一級菜單欄



3)第二級菜單欄



4)第三級菜單欄



5)成功登陸展示



提示:在用普通用戶登陸跳板機連接後端服務器的時候,普通用戶按Crtl+c和Ctrl+z是沒有效果的,所以普通用戶只能直接連接到後端的服務器而不能直接登陸到跳板機終端
本文出自 “wsyht90的博客” 博客,請務必保留此出處http://wsyht2015.blog.51cto.com/9014030/1793101
Copyright © Linux教程網 All Rights Reserved