Demo Effect:
1. Level menu
650) this.width=650; "style=" Float:none; "title=" 1.JPG "alt=" wkiol1rpyy_rdwajaakeinqnrpw366.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m00/53/84/wkiol1rpyy_rdwajaakeinqnrpw366.jpg "/>
2, Level two menu
650) this.width=650; "style=" Float:none; "title=" 2.JPG "alt=" wkiom1rpyruxwsfxaad0epsm7ag793.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m00/53/86/wkiom1rpyruxwsfxaad0epsm7ag793.jpg "/>
3. Perform operation
650) this.width=650; "style=" Float:none; "title=" 3.JPG "alt=" wkiol1rpyzdiia2caaew_y3jwly244.jpg "src="/HTTP/ S3.51cto.com/wyfs02/m01/53/84/wkiol1rpyzdiia2caaew_y3jwly244.jpg "/>
Script reference:
#!/bin/bash#author lic (oldboy linux student) #date 1304disk_no= "/dev/sda1" NGINX_DIR= "/usr/ Local/tdoa/nginx/sbin/nginx "mysql_dir="/usr/local/tdoa/mysql/bin/mysqld_safe "server1=" WEB "SERVER2=" MYSQL " Server1_start= "/usr/local/tdoa/nginx/sbin/nginx" server1_stop= "kill -quit " cat /usr/local/tdoa/ Logs/nginx/nginx.pid ' "server1_restart=" kill -hup ' Cat /usr/local/tdoa/logs/nginx/nginx.pid ' " Server2_start= "/etc/init.d/mysql start" server2_stop= "/etc/init.d/mysql stop" SERVER2_RESTART= "/etc/ Init.d/mysql restart "#dateDATE = ' date + '%y-%m-%d %h:%m:%s" ' #ipIPADDR = ' ifconfig eth0|grep ' inet addr ' |sed ' s/^.*addr://g ' |sed ' s/bcast:.*$//g ' #hostnameHOSTNAME = ' hostname -s ' #userUSER = ' whoami ' #disk_checkDISK_SDA = ' df -h | grep $DISK _no | awk ' {print $5} ' #cpu_average_checkcpu_uptime = ' cat /proc/loadavg | cut -c1-14 ' # Process_checkfunction process_chEck () {for dir in $NGINX _dir $MYSQL _dirdoprocess_count=$ (ps -ef | grep "$dir" | grep -v grep | wc -l) For service in nginx mysql doecho "$dir" |grep -q "$service" IF&NBSP;[&NBSP;$?&NBSP;-EQ&NBSP;0&NBSP;] thenif [ $process _count -eq 0 ]thenecho "$service ............... [Not run] "elseecho " $service ......... ....... [RUNNING] "continuefifidonedone}declare flag=0clearwhile [ " $flag " -eq 0 ]doecho "========================================" process_checkecho "====================================== = = "Cat << eof|-----------system infomation-----------| date &NBSP;&NBSP;&NBSP: $DATE | hostname : $HOSTNAME | user : $USER | ip &NBSP: $IPADDR | disk_used : $DISK _sda| cpu_average: $cpu _ Uptime----------------------------------------|****please enter your choice:[0-5]****|--------- -------------------------------(1) Configure $SERVER 1 service (2) Configure $SERVER 2 service (3) configure networke service (4) change passwd (5) Logs (0) quiteofread -p "please enter your choice[0-5]: " inputcase $input in#web service1) clearwhile [ "$flag" -eq 0 ]docat << EOF----------------------------------------|****please enter your choice:[0-3]****|------------ ----------------------------(1) Start $SERVER 1 service (2) Stop $SERVER 1 service ( 3) ReStart $SERVER 1 service (0) BackEOF read -p "Please enter your choice[0-3]: " input1 case $input1 in 1) echo -e "\n>>>>>>>>>>> $DATE Start $SERVER 1 ">>/log.txt $SERVER 1_start 2>>/log.txt if [ $? == 0 ];then echo "start $SERVER 1 ...................................................... [OK] " else echo " start $SERVER 1 ...................................................... [FAILED] " fi sleep 5 clear ;; &NBSP;2) echo -e "\n>>>>>>>>>>> $DATE stop $SERVER 1 ">>/log.txt $SERVER 1_stop 2>>/log.txt if [ $? == 0 ];then echo "stop $SERVER 1 ....................................................... [OK] " else echo " stop $SERVER 1 ..... ............................................ [FAILED] " fi sleep 5 clear ;; 3) echo -e "\n>>>>>>>>>>> $DATE restart $SERVER 1 ">>/log.txt /usr/local/tdoa/php/sbin/php-fpm restart 2>>/ log.txt $SERVER 1_restart 2>>/log.txt if [ $? == 0 ]; then echo "restart $SERVER 1 ...... ..... ....... ............................ [OK] " else echo " restart $SERVER 1 .................................................... [FAILED] " fi sleep 5 clear ;; 0) clear break ;; *) echo "----------------------------------" echo "| warning!!! | " echo "| please enter right choice! | " echo "----------------------------------" for i in ' seq -w 10 -1 1 ' do echo -ne "\b\b$i"; sleep 1; done clear ;; esac done;; #mysql service2) clearwhile [ "$flag" -eq 0 ]docat << EOF----------------------------------------|****please enter your choice:[0-3]****|------------ ----------------------------(1) Start $SERVER 2 service (2) Stop $SERVER 2 service ( 3) ReStart $SERVER 2 service (0) BackEOF read -p "Please enter your Choice[0-3]: " input2 case $input 2 in 1) echo -e "\n>>>>>>>>>>> $DATE Start $SERVER 2" >>/ log.txt $SERVER 2_start 2>>/log.txt if [ $? == 0 ]; then echo "start $SERVER 2 ...... ..... ..... ............................... [OK] " else echo " start $SERVER 2 ...................................................... [FAILED] " fi sleep 5 clear ;; &NBSP;2) echo -e "\n>>>>>>>>>>> $DATE stop $ SERVER2 ">>/log.txt $SERVER 2_stop 2>>/log.txt if [ $? == 0 ];then echo "stop $SERVER 2 ....................................................... [OK] " else echo " stop $SERVER 2 ....................................................... [FAILED] " fi sleep 5 clear ;; 3) echo -e "\n>>>>>>>>>>> $DATE restart $SERVER 2 ">>/log.txt $SERVER 2_restart 2>>/log.txt if [ $ ? == 0 ];then echo "restart $SERVER 2 .................................................... [OK] " else echo " restart $SERVER 2 .................................................... [FAILED] " fi sleep 5 clear ;; 0) clear break ;; *) echo "----------------------------------" echo "| warning!!! | " echo "| please enter right  choice! | " echo "----------------------------------" for i in ' seq -w 10 -1 1 ' do echo -ne "\b\b$i"; sleep 1; done clear ;; esac done;; #网络服务3) clearwhile [ "$flag" -eq 0 ]docat << EOF----------------------------------------|****please enter your choice:[0-3]****|------------ ----------------------------(1) restart network service (2) Configure NETWORK Service (0) BackEOF read -p "please enter your choice[0-3]: " input3 case $input 3 in 1) echo -e "\n>>>>>> >>>>> $DATE restart network ">>/log.txt /etc/init.d/network Restart 2>>/log.txt if [ $? == 0 ];then echo "Restart The Network ... ..... ..... ..... ..... ........................... [OK] " else echo " restart network ..................................................... [FAILED] " fi sleep 5 clear ;; &NBSP;2) clear setup clear ;; 0) clear break ;; *) echo "----------------------------------" echo "| warning!!! | " echo "| please enter right choice! | " echo "----------------------------------" for i in ' seq -w 10&nbsP;-1 1 ' do echo -ne "\b\b$i"; sleep 1; done clear ;; esac done;; 4) clearwhile [ "$flag" -eq 0 ]docat << EOF----------------------------------------|****please enter your choice:[0-3]****|------------ ----------------------------(1) change root passwd (2) change samba passwd (0) BackEOF read -p "please enter your choice[0-3]: " input5 case $input 5 in 1) echo -e "\n>>>>>>>>>>> $DATE change system administertor root passwd\n ">>/log.txt passwd root 2>>/log.txt if [ $? == 0 ];then echo "change root passwd .......................................... [OK] " else echo " change root passwd ..................................................... [FAILED] " fi sleep 5 clear ;; &NBSP;2) echo -e "\n>>>>>>>>>>> $DATE change &NBSP;SAMBA&NBSP;PASSWD ">>/log.txt smbpasswd -a tdoa 2>>/log.txt if [ $? == 0 ];then echo "change samba passwd ..................................................... [OK] " else echo " change samba passwd ..................................................... [FAILED] " fi sleep 5 clear ;; 0) clear break ;; *) echo "----------------------------------" echo "| warning!!! | " echo "| please enter right choice! | " echo "----------------------------------" sleep 8 clear ;; Esacdone;; 5) clearecho "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "|" less /log.txtecho "|" echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";; 0) clearexit 0;; *) echo "----------------------------------" echo "| warning!!! | " echo "| please enter right choice! |" echo "----------------------------------" for i in ' Seq&nbsP;-w 10 -1 1 ' do echo -ne "\b\b$i"; sleep 1; done clear;; Esacdone
This article is from the "Old boy Linux ops" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/1577622
Multi-level menu system Installation Maintenance Shell script implementation Enterprise case