进程监控脚本

#!/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

作者:ahyswang 发表于2014-10-11 22:34:45 原文链接
阅读:111 评论:0 查看评论

你可能感兴趣的:(脚本,进程)