进程监控脚本

#!/bin/sh

my_ip=`/sbin/ifconfig eth1 | grep 'inet addr' | awk  '{print substr($2, index($2, ":")+1)}'`
recv=""
msg="not_existing, restart ..."
MONITOR_LOG="monitor.log"


#monitor procname scriptname
monitor()
{
        # 查找进程
    pgrep ^$1$ > /dev/null

    # 如果不存在, 就重启他.
    if [ $? -ne 0 ] ; then
                echo "`date` ${my_ip}.$1 $msg";
        $2 restart
    fi

    sleep 2
}

echo "`date` monitor begin ..." >> ../log/monitor.log

monitor "server" "/home/rti/rti/scripts/Server.sh" >> ${MONITOR_LOG}
monitor "connector" "/home/rti/rti/scripts/Connector.sh" >> ${MONITOR_LOG}

echo "`date` monitor end ..." >> ../log/monitor.log

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。