码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2015-11-26 19:23:32      阅读:252      评论:0      收藏:0      [点我收藏+]

标签: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

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

标签:shell脚本

原文地址:http://chentp.blog.51cto.com/10638759/1717141

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!