标签:shell脚本
本文是之前的watchdate的shell脚本的改进wdate,同样先上图:
1)脚本加入chkconfig管理
head -5 /etc/init.d/wdate
#!/bin/bash #auth:chentp0601@qq.com # #wdate Start/Stop the watchdate daemon # # chkconfig: 2345 71 55
chkconfig --add wdate
2)开始贴代码
#!/bin/bash #auth:chentp0601@qq.com # #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
本文出自 “前进吧菜鸟” 博客,请务必保留此出处http://chentp.blog.51cto.com/10638759/1717141
标签:shell脚本
原文地址:http://chentp.blog.51cto.com/10638759/1717141