apache操作员重启脚本这里是费话可以不看:
只有从日常的管理工作中抽出一些可以自动化地操作,才是一下真真的管理者,系统管理员也要将日常的工作转化为标准的操作流程,让操作员为我们完成日常的重复性工作,这样才能体现一个管理员的价值。
以下是程序说明:
Apache System Manage
1.Show Apache Process //查看apache进程
2.Start Apache //启动apache进程
3.Stop Apache //停止apache进程
4.Restart Apache //重启apache进程
5.Force Stop Apache //kill方式停apache进程
0.exit //退出程序
使用方法:如果只是让操作进行最简单的操作的话可以使用以下命令,将登陆用户的shell改与脚本所在的目录:
如:/home/wood016/apachctl.sh
记得要加入可执行权限。
# chmod u+x /home/wood016/apachctl.sh
# ls -l /home/wood016/apachctl.sh
-rwxr----- 1 wood016 wood016 3088 12-21 00:39 apachctl.sh
# usermod -s /home/wood016/apachctl.sh wood016
# finger wood016
Login: modl Name: (null)
Directory: /home/wood016 Shell: /home/wood016/apachctl.sh
Never logged in.
No mail.
No Plan.
#linux菜单程序
以下是程序源代码:
source code:
#!/bin/bash
# this script just for operator to deal with apache
#
# apache path
AP=/usr/sbin/httpd
APACHE (){
OP=$1
case $OP in
stop)
sudo ${AP} -k stop
if [ $? -eq 0 ];then
echo "apache stoped."
fi
;;
start)
sudo ${AP} -k start
;;
restart)
sudo ${AP} -k restart
if [ $? -eq 0 ];then
echo "apache restartd."
fi
;;
status)
CNT=`ps -ef |grep httpd |grep -v grep |wc -l`
if [ ${CNT} -gt 0 ];then
echo -n "apache is running."
fi
;;
forcestop)
sudo kill -9 `ps -ef |grep httpd |grep -v grep |awk '{print $2} '|sort -u`
CNT=`ps -ef |grep httpd |grep -v grep |wc -l`
if [ $? -eq 0 && ${CNT} -gt 0 ];then
echo -n "apache is running."
else
echo -n "apache stoped."
fi
;;
*)
exit 1
;;
esac
}
while true
do
clear
BLN=1
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "Apache System Manage"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "*********************************"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "1. Show Apache Process"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "2. Start Apache"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "3. Stop Apache"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "4. Restart Apache"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "5. Force Stop Apache"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
BLN=`expr ${BLN} + 1`
echo -n "0. Exit"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "*********************************"
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "Please type in the option[0-5]:"
BLN=`expr ${BLN} + 1`
read YASM
case $YASM in
1)
#echo -n "Show Apache Process."
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 0
ps -ef |grep httpd |grep -v grep
LN=`ps -ef |grep httpd |grep -v grep |wc -l`
BLN=`expr ${BLN} + ${LN} + 1`
tput cup ${BLN} 24
echo -n "Summary process is : ${LN}"
tput cup `expr ${BLN} + 2` 24
echo -n "Enter come back."
;;
2)
#echo -n "Start Apache."
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "Start apache now (yes|no):"
read ANS
if [ ${ANS}X == "yesX" ];then
APACHE start
tput clear
tput cup ${BLN} 24
echo -n "Apache Started"
fi
tput cup `expr ${BLN} + 2` 24
echo -n "Enter come back."
;;
3)
#echo -n "Stop Apache."
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "Stop apache now (yes|no):"
read ANS
if [ ${ANS}X == "yesX" ];then
APACHE stop
tput clear
tput cup ${BLN} 24
echo -n "Apache Stoped"
fi
tput cup `expr ${BLN} + 2` 24
echo -n "Enter come back."
;;
4)
#echo -n "Restart Apache."
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "Restart apache now (yes|no):"
read ANS
if [ ${ANS}X == "yesX" ];then
APACHE restart
tput clear
tput cup ${BLN} 24
echo -n "Apache Restarted"
fi
tput cup `expr ${BLN} + 2` 24
echo -n "Enter come back."
;;
5)
#echo -n "Force Stop Apache."
BLN=`expr ${BLN} + 1`
tput cup ${BLN} 24
echo -n "Force Stop apache now (yes|no):"
read ANS
if [ ${ANS}X == "yesX" ];then
APACHE forcestop
tput clear
tput cup ${BLN} 24
echo -n "Apache Force Stoped"
fi
tput cup `expr ${BLN} + 2` 24
echo -n "Enter come back."
;;
0|q|Q)
exit
;;
*)
tput cup `expr ${BLN} + 2` 24
echo "Input Error!"
;;
esac
read WAITT
done
欢迎转载,请注明来源:wood016.cublog.cn
谢谢