demopu教你学linux,shell实现简单的进程监控脚本
2015-04-13 09:35
567 查看
一个简单的需求:shell实现进程监控watchdog功能,配合计划任务每分钟执行一次shell脚本,对进程进行监控,如果意外中断那么启动他,如果正常则什么都不需要去做。
#!/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
学习更多:http://www.demopu.com/?p=247
#!/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
学习更多:http://www.demopu.com/?p=247
相关文章推荐
- shell实现简单的进程监控脚本
- Shell脚本实现Linux系统和进程资源监控
- Shell脚本实现Linux系统和进程资源监控
- shell 脚本对 Linux 系统和进程资源进行监控
- shell脚本实现某一进程是否运行结束的监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- linux 进程监控和自动重启的简单实现
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 【Shell/Python】Linux 进程自动监控bash shell脚本 监控VPS服务器负载/CPU及内存占用 自动重启
- 使用Shell脚本对Linux系统和进程资源进行监控(转)
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- linux下如何自动检测并重新启动一个死掉的进程,然后再把它杀死:)(shell脚本实现)
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控