Shell字符菜单管理

1.编写menu函数,后续被调用。 

#!/bin/bash
#menu.sh
function menu() {

time=`date '+%Y-%m-%d %T'`

cat << eof
####################################
             Menu
####################################
*    1) stop  apache, mysql
*    2) start apache, mysql
*    3) shutdown system
*    4) quit
####################################
     $time
####################################
eof
}

2.输入选项关闭相应服务,如Apache、Mysql

#!/bin/bash
#mangeLAMP
. menu.sh
clear
menu

while true
do
read -p "please input your choice:" option

case $option in 
	 
	 1)
		service httpd stop
		if [ $? -eq 0 ]; then
			echo "httpd is stoped"
		else
			echo "httpd is not stoped"
		fi

		service mysql stop
		if [ $? -eq 0 ]; then
			echo "mysql is stoped"
		else
			echo "mysql is not stoped"
		fi

		;;
	 2)
		service httpd start
		if [ $? -eq 0 ]; then
			echo "httpd is started"
		else
			echo "httpd is not started"
		fi

		service mysql start
		if [ $? -eq 0 ]; then
			echo "mysql is started"
		else
			echo "mysql is not started"
		fi

		;;
	 3)
		poweroff
		echo "The system is poweroff...."
		;;
   	 4)
		break
		;;
      *)
		echo "Caution! Please input choice: 1~4!!"
		;;
esac
done

3.测试sh manageLAMP.sh

####################################
             Menu
####################################
*    1) stop  apache, mysql
*    2) start apache, mysql
*    3) shutdown system
*    4) quit
####################################
     2018-09-17 22:38:39
####################################
please input your choice:1
Stopping httpd: [  OK  ]
httpd is stoped
Shutting down MySQL.. SUCCESS! 
mysql is stoped
please input your choice:4  
[root@REDHAT html]# 
####################################
             Menu
####################################
*    1) stop  apache, mysql
*    2) start apache, mysql
*    3) shutdown system
*    4) quit
####################################
     2018-09-17 22:40:35
####################################
please input your choice:2
Starting httpd: [  OK  ]
httpd is started
Starting MySQL. SUCCESS! 
mysql is started
please input your choice:4
[root@REDHAT html]# 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值