linux bash启动停止脚本,第二弹

本文是之前的watchdate的shell脚本的改进wdate,同样先上图:

wKioL1ZWwy_juP9NAARfY7_6zMo324.jpg

1)脚本加入chkconfig管理

 head -5 /etc/init.d/wdate 

#!/bin/bash
#auth:[email protected]
#
#wdate         Start/Stop the watchdate daemon
#
# chkconfig: 2345 71 55

chkconfig --add wdate


2)开始贴代码

#!/bin/bash
#auth:[email protected]
#
#wdate         Start/Stop the watchdate daemon
#
# chkconfig: 2345 71 55
source /etc/init.d/functions
startwdate(){
nohup watch -n 1 date "+%H:%M:%S" &> /tmp/date &
[ $? -eq 0 ] && action "starting $0" /bin/true||action "starting $0" /bin/false
}
stopwdate(){
pkill watch
[ $? -eq 0 ] && action "stoping $0" /bin/true||action "stoping $0" /bin/false
}
statuswdate(){
status=`ps -ef |grep -v grep|grep "watch -n"|wc -l`
[ $status -ne 0 ] && action "status of $0 is running" /bin/true||action "status of $0 is stoped" /bin/false
}
#判断参数个数
[ $# -ne 1 ]&&{
echo "usage:$0 {start|stop|restart|status}"
exit 1
}
#分支
case $1 in
start)
startwdate
;;
stop)
stopwdate
;;
restart)
stopwdate
startwdate
;;
status)
statuswdate
;;
*)
echo "usage:$0 {start|stop|restart|status}"
;;
esac



你可能感兴趣的:(shell脚本)