多級菜單系統安裝維護shell指令碼實現企業級案例

來源:互聯網
上載者:User

標籤:shell編程   菜單   老男孩培訓   

示範效果:

1、一級菜單

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、二級菜單

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、執行操作

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" />

指令碼參考:

#!/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 [ $? -eq 0 ]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       :$DATE| HOSTNAME   :$HOSTNAME| USER       :$USER| IP         :$IPADDR| DISK_USED  :$DISK_SDA| CPU_AVERAGE:$cpu_uptime----------------------------------------|****Please Enter Your Choice:[0-5]****|----------------------------------------(1) Configure $SERVER1 Service(2) Configure $SERVER2 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 $SERVER1 Service(2) Stop $SERVER1 Service(3) ReStart $SERVER1 Service(0) BackEOF read -p "Please enter your choice[0-3]: " input1 case $input1 in  1)  echo -e "\n>>>>>>>>>>>$DATE Start $SERVER1">>/log.txt  $SERVER1_START 2>>/log.txt  if [ $? == 0 ];then   echo "Start $SERVER1......................................................[OK]"  else    echo "Start $SERVER1......................................................[FAILED]"  fi  sleep 5  clear  ;; 2)    echo -e "\n>>>>>>>>>>>$DATE Stop $SERVER1">>/log.txt  $SERVER1_STOP 2>>/log.txt  if [ $? == 0 ];then   echo "Stop $SERVER1.......................................................[OK]"  else    echo "Stop $SERVER1.......................................................[FAILED]"  fi  sleep 5  clear  ;; 3)   echo -e "\n>>>>>>>>>>>$DATE ReStart $SERVER1">>/log.txt  /usr/local/tdoa/php/sbin/php-fpm restart 2>>/log.txt  $SERVER1_RESTART 2>>/log.txt  if [ $? == 0 ];then   echo "Restart $SERVER1....................................................[OK]"  else    echo "Restart $SERVER1....................................................[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 $SERVER2 Service(2) Stop $SERVER2 Service(3) ReStart $SERVER2 Service(0) BackEOF read -p "Please enter your Choice[0-3]: " input2 case $input2 in  1)  echo -e "\n>>>>>>>>>>>$DATE Start $SERVER2">>/log.txt  $SERVER2_START 2>>/log.txt  if [ $? == 0 ];then   echo "Start $SERVER2......................................................[OK]"  else    echo "Start $SERVER2......................................................[FAILED]"  fi  sleep 5  clear  ;; 2)  echo -e "\n>>>>>>>>>>>$DATE Stop $SERVER2">>/log.txt  $SERVER2_STOP 2>>/log.txt  if [ $? == 0 ];then   echo "Stop $SERVER2.......................................................[OK]"  else    echo "Stop $SERVER2.......................................................[FAILED]"  fi  sleep 5  clear  ;; 3)   echo -e "\n>>>>>>>>>>>$DATE ReStart $SERVER2">>/log.txt  $SERVER2_RESTART 2>>/log.txt  if [ $? == 0 ];then   echo "Restart $SERVER2....................................................[OK]"  else    echo "Restart $SERVER2....................................................[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 $input3 in 1)   echo -e "\n>>>>>>>>>>>$DATE ReStart Network">>/log.txt  /etc/init.d/network restart  2>>/log.txt  if [ $? == 0 ];then   echo "Restart Network.....................................................[OK]"  else    echo "Restart Network.....................................................[FAILED]"  fi  sleep 5  clear  ;; 2)      clear  setup  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;;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 $input5 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  ;; 2)   echo -e "\n>>>>>>>>>>>$DATE Change Samba 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 -w 10 -1 1`   do     echo -ne "\b\b$i";     sleep 1;   done clear;;esacdone

 

本文出自 “老男孩linux營運” 部落格,請務必保留此出處http://oldboy.blog.51cto.com/2561410/1577622

多級菜單系統安裝維護shell指令碼實現企業級案例

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.