Shell实现多级菜单系统安装维护脚本实例分享

演示效果:

1、一级菜单

2、二级菜单

3、执行操作

脚本参考:

代码如下:

#!/bin/bash
#author lic(oldboy linux student)
#date 1304
DISK_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"
#date
DATE=`date +"%y-%m-%d %H:%M:%S"`
#ip
IPADDR=`ifconfig eth0|grep 'inet addr'|sed 's/^.*addr://g' |sed 's/Bcast:.*$//g'`
#hostname
HOSTNAME=`hostname -s`
#user
USER=`whoami`
#disk_check
DISK_SDA=`df -h | grep $DISK_NO | awk '{print $5}'`
#cpu_average_check
cpu_uptime=`cat /proc/loadavg | cut -c1-14`
#process_check
function process_check() {
for dir in $NGINX_DIR $MYSQL_DIR
do
process_count=$(ps -ef | grep "$dir" | grep -v grep | wc -l)
for service in nginx mysql
do
echo "$dir" |grep -q "$service"
if [ $? -eq 0 ]
then
if [ $process_count -eq 0 ]
then
echo "$service.......................[NOT RUN]"
else
echo "$service.......................[RUNNING]"
continue
fi
fi
done
done
}
declare flag=0
clear
while [ "$flag" -eq 0 ]
do
echo "========================================"
process_check
echo "========================================"
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) Quit
EOF
read -p "Please enter your choice[0-5]: " input
case $input in
#web service
1)
clear
while [ "$flag" -eq 0 ]
do
cat << EOF
----------------------------------------
|****Please Enter Your Choice:[0-3]****|
----------------------------------------
(1) Start $SERVER1 Service
(2) Stop $SERVER1 Service
(3) ReStart $SERVER1 Service
(0) Back
EOF
 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 service
2)
clear
while [ "$flag" -eq 0 ]
do
cat << EOF
----------------------------------------
|****Please Enter Your Choice:[0-3]****|
----------------------------------------
(1) Start $SERVER2 Service
(2) Stop $SERVER2 Service
(3) ReStart $SERVER2 Service
(0) Back
EOF
 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)
clear
while [ "$flag" -eq 0 ]
do
cat << EOF
----------------------------------------
|****Please Enter Your Choice:[0-3]****|
----------------------------------------
(1) ReStart NETWORK Service
(2) Configure NETWORK Service
(0) Back
EOF
 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)
clear
while [ "$flag" -eq 0 ]
do
cat << EOF
----------------------------------------
|****Please Enter Your Choice:[0-3]****|
----------------------------------------
(1) Change ROOT Passwd
(2) Change Samba Passwd
(0) Back
EOF
 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
 ;;
esac
done
;;
5)
clear
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "|"
less /log.txt
echo "|"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
;;
0)
clear
exit 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
;;
esac
done

(0)

相关推荐

  • Shell实现多级菜单系统安装维护脚本实例分享

    演示效果: 1.一级菜单 2.二级菜单 3.执行操作 脚本参考: 复制代码 代码如下: #!/bin/bash #author lic(oldboy linux student) #date 1304 DISK_NO="/dev/sda1" NGINX_DIR="/usr/local/tdoa/nginx/sbin/nginx" MYSQL_DIR="/usr/local/tdoa/mysql/bin/mysqld_safe" SERVER1=&

  • 超详细的5个Shell脚本实例分享(值得收藏)

    概述 今天主要分享5个shell脚本实例,大家可以借鉴下里面的思路,看下有没另外一种实现方式. 1.定时清空文件内容,定时记录文件大小 #!/bin/bash ################################################################ #每小时执行一次脚本(任务计划),当时间为0点或12点时,将目标目录下的所有文件内 #容清空,但不删除文件,其他时间则只统计各个文件的打小,一个文件一行,输出到以时#间和日期命名的文件中,需要考虑目标目录下二级

  • WordPress中访客登陆实现邮件提醒的PHP脚本实例分享

    登陆邮件提醒实现方法 前提是空间有邮件功能,测试有无邮件功能的方法:登录界面点击"忘记密码",有邮件发到你邮箱就有邮件功能. 一.登录成功提醒 就像银行的登录提醒一样,如果有人登录了系统,就会发一封邮件到邮箱,提醒你有人登录了,如果当时不是你登录,就要引起警惕了.将以下代码放入主题的functions.php中: /***************************************************** 函数名称:wp_login_notify v1.0 by DH.

  • js实现适用于素材网站的黑色多级菜单导航条效果

    本文实例讲述了js实现适用于素材网站的黑色多级菜单导航条效果.分享给大家供大家参考.具体如下: 这是一款适用于素材网站的黑色多级菜单导航条,无需jQuery,采用CSS+javaScript来实现,整体效果非常棒,用来学习CSS也是很不错的. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-black-color-nav-style-codes/ 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD X

  • 非常实用的23个Shell脚本实例

    shell脚本是帮助程序员和系统管理员完成费时费力的枯燥工作的利器,是与计算机交互并管理文件和系统操作的有效方式.区区几行代码,就可以让计算机接近按照你的意图行事. 为大家整理了23个实例,通过23个实战经典脚本实例,展示了shell脚本编程的实用技术和常见工具用法.大家只需根据自己的需求,将文中这些常见任务和可移植自动化脚本推广应用到其他类似问题上,能解决那些三天两头碰上的麻烦事. #!/bin/bash ##################################### #检测两台服

  • php管理nginx虚拟主机shell脚本实例

    本文实例讲述了php管理nginx虚拟主机shell脚本,分享给大家供大家参考.具体分析如下: 使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考: 复制代码 代码如下: #!/usr/bin/php -q <?php   start: fwrite(STDOUT,"===========Vhost Script===========\n"); fwrite(STDOUT,"=

  • Bootstrap组件之下拉菜单,多级菜单及按钮布局方法实例

    本文实例讲述了Bootstrap组件之下拉菜单,多级菜单及按钮布局方法.分享给大家供大家参考,具体如下: 下拉菜单 菜单: ,dropdown(.dropup改变这个是上显示)   data-toggle="dropdown" (激活文本处)      .dropdown-menu   .pull-left   .pull-right 按钮组:.btn-group(各种类为btn的标签集合)    .btn-toolbar(按钮导航条)  .btn-group-vertical   .

  • 输出执行操作和打印日志的shell脚本实例

    cat /mnt/log_function.sh #!/bin/bash #log function ####log_correct函数打印正确的输出到日志文件 function log_correct () { DATE=`date "+%Y-%m-%d %H:%M:%S"` ####显示打印日志的时间 USER=$(whoami) ####那个用户在操作 echo "${DATE} ${USER} execute $0 [INFO] $@" >>/v

  • jquery实现带渐变淡入淡出并向右依次展开的多级菜单效果实例

    本文实例讲述了jquery实现带渐变淡入淡出并向右依次展开的多级菜单效果.分享给大家供大家参考.具体如下: 这是一款核心基于jquery的多级导航菜单特效,横向向右依次展开菜单项,当然本菜单并不是完美的,因此没有怎么美化,另外包括子菜单的上级菜单中缺少一个菜单标记,这样用户有时候不知道哪个菜单中含有下级子菜单.不过添加这样一个标记似乎挺简单,你可以自己动手添加吧. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/jquery-right-show

  • 实现自动清除日期目录shell脚本实例代码

    实现自动清除日期目录shell脚本实例代码 很多时候备份通常会使用到基于日期来创建文件夹,对于这些日期文件夹下面又有很多子文件夹,对于这些日期文件整个移除,通过find结合rm或者delete显得有些力不从心.本文提供一个简单的小脚本,可以嵌入到其他脚本,也可直接调用,如下文供大家参考. 1.脚本内容 [root@SZDB ~]# more purge_datedir.sh #!/bin/bash # Author: Leshami # Blog : http://blog.csdn.net/l

随机推荐