加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 07:17:09 所属栏目:安全 来源:网络整理
导读:#!/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 21 case "$?" in 0) # It is running in this case so we do nothing. echo "$NAME is RUNNING OK. Relax." $NOP

#!/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脚本,对进程进行监控,如果意外中断那么启动他,如果正常则什么都不需要去做。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读