Linux下Dialog+Shell三层目录专业规范跳板机脚本

#Dialog+Shell介绍

Dialog+Shell结合使用,方能体现出Dialog图形化的效果,在运维的时候,使用图形化界面,能给你一个更直观的感受,相信你会喜欢上他的i_f05.gif



#创建脚本目录 

[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)普通用户登陆

wKioL1dv9gqwB93NAAB_nL-6Bj8780.png-wh_50


2)第一级菜单栏

wKioL1dv96fTlR_fAAAmhyg6ASY618.png-wh_50


3)第二级菜单栏

wKiom1dv96igyIJFAAAuqAdGSDM157.png-wh_50


4)第三级菜单栏

wKioL1dv96jxpjeDAAAxh6PYuQ0922.png-wh_50


5)成功登陆展示

wKiom1dv96nztLh-AABKCGOyj3M281.png-wh_50


提示:在用普通用户登陆跳板机连接后端服务器的时候,普通用户按Crtl+c和Ctrl+z是没有效果的,所以普通用户只能直接连接到后端的服务器而不能直接登陆到跳板机终端


优秀的个人博客,低调大师

微信关注我们

原文链接:https://blog.51cto.com/yht1990/1793101

转载内容版权归作者及来源网站所有!

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

相关文章

发表评论

资源下载

更多资源
Oracle Database,又名Oracle RDBMS

Oracle Database,又名Oracle RDBMS

Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的、适应高吞吐量的数据库方案。

Eclipse(集成开发环境)

Eclipse(集成开发环境)

Eclipse 是一个开放源代码的、基于Java的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse 附带了一个标准的插件集,包括Java开发工具(Java Development Kit,JDK)。

Java Development Kit(Java开发工具)

Java Development Kit(Java开发工具)

JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。

Sublime Text 一个代码编辑器

Sublime Text 一个代码编辑器

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。