반응형

 


[쉘 스크립트]
---------------------------------------------------------------------

#!/usr/bin/ksh

while [ true ]
do

NOW_DATE_YYYYMMDD=`date '+%Y%m%d'`
NOW_DATE_YYYYMMDDHH=`date '+%Y%m%d%H'`
NOW_DATE_YYYYMMDDHHMMSS=`date '+%Y%m%d%H%M%S'`

FAIL_LOG_FILE=$NOW_DATE_YYYYMMDDHH.FAIL
OKAY_LOG_FILE=$NOW_DATE_YYYYMMDDHH.OKAY

PROCESS_NAME=MyProcess

PROCESS_CNT=`ps -ef | grep $PROCESS_NAME | grep -v grep | grep -v more |grep -v head | grep -v tail | grep -v vi | wc -l | awk '{print $1}'`

if [ $PROCESS_CNT -eq 0 ]
then
    if [ -f $FAIL_LOG_FILE ]
    then
        echo "[$NOW_DATE_YYYYMMDDHHMMSS][$PROCESS_NAME][PROCESS_CNT]..........[$PROCESS_CNT]...[Dead.....]"  >> $FAIL_LOG_FILE
    else
        echo "[$NOW_DATE_YYYYMMDDHHMMSS][$PROCESS_NAME][PROCESS_CNT]..........[$PROCESS_CNT]...[Dead.....]"  >  $FAIL_LOG_FILE
    fi
else
    if [ -f $OKAY_LOG_FILE ]
    then
        echo "[$NOW_DATE_YYYYMMDDHHMMSS][$PROCESS_NAME][PROCESS_CNT]..........[$PROCESS_CNT]...[Alive....]"  >> $OKAY_LOG_FILE
    else
        echo "[$NOW_DATE_YYYYMMDDHHMMSS][$PROCESS_NAME][PROCESS_CNT]..........[$PROCESS_CNT]...[Alive....]"  >  $OKAY_LOG_FILE
    fi
fi

sleep 10

done

---------------------------------------------------------------------


[결과]

---------------------------------------------------------------------

2013110610.FAIL

[20131106100126][MyProcess][PROCESS_CNT]..........[0]...[Dead.....]
[20131106100136][MyProcess][PROCESS_CNT]..........[0]...[Dead.....]
[20131106100146][MyProcess][PROCESS_CNT]..........[0]...[Dead.....]

2013110610.OKAY

[20131106100210][MyProcess][PROCESS_CNT]..........[1]...[Alive....]
[20131106100220][MyProcess][PROCESS_CNT]..........[1]...[Alive....]
[20131106100231][MyProcess][PROCESS_CNT]..........[1]...[Alive....]

---------------------------------------------------------------------

 

 

반응형
Posted by 공간사랑
,