linux进程监控,monitor脚本

由于服务器上一些进程莫名的挂掉,需要些一个monitor的bash脚本来监控这些进程:

#! /bin/bash
#chkconfig info
### BEGIN INIT INFO
# Provides:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description:
### END INIT INFO

MYSQL_NAME='mysql'
APACHE_NAME='http'

function check_process {
            search_string=$1
            search_result=nmap localhost|grep -P $1'$'|awk '{print $3}'|grep $search_string
            echo $search_result
            if [ "$search_result" = "$search_string" ]
            then
                echo $"Still exist!"
            else
                echo $"Not exist!"
                /opt/lampp/lampp start >> /dev/null
                echo $"Lampp restart!"
                echo $"Lampp stop unexpectedly, now it restart by cron!" | mail -s "Breamweb error!" 13482746059@139.com
            fi
}
case "$1" in
      start)
            /opt/lampp/lampp start
            ;;
      stop)
            /opt/lampp/lampp stop
            ;;

monitor)
check_process $MYSQL_NAME
check_process $APACHE_NAME
;;
esac
exit 0

undefined

crontab:

/1 * * * /etc/init.d/

Original: https://www.cnblogs.com/wangkangluo1/p/3645701.html
Author: wangkangluo1
Title: linux进程监控,monitor脚本

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/8495/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总