Linux process monitoring, monitor script

Since some processes on the server hang inexplicably, a monitor bash script is needed to monitor these processes:

#! /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!" [email protected]
            be
}

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


crontab:

*/1 *  * * * /etc/init.d/<script_name> monitor >> /var/log/cron.<script_name>.monitor.log 2>&1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326426181&siteId=291194637