先贴效果:
#!/bin/bash #auth:chentp0601@qq.com source /etc/init.d/functions #判断参数个数 [ $# -ne 1 ]&&{ echo "usage:$0 {start|stop|restart|status}" exit 1 } #分支 case $1 in start) nohup watch -n 1 date "+%H:%M:%S" &> /tmp/date & action "starting $0" /bin/true ;; stop) pkill watch action "stoping $0" /bin/true ;; restart) pkill watch nohup watch -n 1 date "+%H:%M:%S" &> /tmp/date & action "restarting $0" /bin/true ;; status) 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 ;; *) echo "usage:$0 {start|stop|restart|status}" ;; esac
转载于:https://blog.51cto.com/chentp/1716825