当前位置: > shell编程 >

shell实现简单的进程监控脚本

时间:2014-04-28 23:36来源:linux.it.net.cn 作者:IT网
#!/bin/bash 
NAME=java 
NOP=/bin/true
DATE=$(/bin/date +"%Y-%m-%d %H:%M:%S") 
ps -ef | awk -F " " '{print $8,$2}' | grep ^java >/dev/null 2>&1
case "$?" in
0) 
# It is running in this case so we do nothing. 
echo "$NAME is RUNNING OK. Relax."
$NOP 
;; 
1) 
echo "$NAME is NOT RUNNING. Starting $NAME and sending notices."
java -jar sms.jar  2>&1 >/dev/null & 
NOTICE=/tmp/watchdog.log 
echo "$NAME was not running and was started on $DATE" >> $NOTICE 
esac 
exit 0 

 

一个简单的需求:shell实现进程监控watchdog功能,配合计划任务每分钟执行一次shell脚本,对进程进行监控,如果意外中断那么启动他,如果正常则什么都不需要去做。

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容