본문 바로가기
IT 이야기 - About IT

[Shell] syslog check 쉘

by 회사원 주씨 2009. 6. 16.
반응형

이 역시 시스템 로그(syslog)를 5분단위로 체크하여 관리자가 지정한 메세지가 보이면

SMS로 알려주도록 만든 쉘이다.

공부하면서 가장 처음으로 만들었던 쉘이라 애정이 간다는 ^^

<사용환경 - HP-UX>

#################################################################################
#
# Syslog Check Script
# Edit By Hyetaek
#
##################################################################################

#!/usr/bin/ksh
A_COUNT=0                                                                                 # syslog count
B_COUNT=`cat /var/adm/syslog/syslog.log | wc -l`                        # syslog Before count
T_COUNT=0                                                                                 # Tail count
M_COUNT=0                                                                                # message count
KEY1=error                                                                                  # Search key
KEY2=ems
KEY3=warning
KEY4=fail
KEY5=fault
RTIME=300                                                                                   # Refresh time(default 5 min)

if [ $1 <> null ];
then
        RTIME=$1
fi

while (true)
do
        A_COUNT=`cat /var/adm/syslog/syslog.log | wc -l`
        # echo $A_COUNT

        if [ $A_COUNT -eq $B_COUNT ];
        then
                sleep $RTIME           
        else
                if [ $A_COUNT -lt $B_COUNT ];
                then
                        B_COUNT=$A_COUNT
                else
                        let T_COUNT=$A_COUNT-$B_COUNT
                        # echo $T_COUNT

                        tail -$T_COUNT /var/adm/syslog/syslog.log | grep -ie $KEY1 -ie $KEY2 -ie $KEY3 >> /var/adm/syslog/
sys_mon/imsi_syslog.txt
                        tail -$T_COUNT /var/adm/syslog/syslog.log | grep -i $KEY4 | grep -iv pam | grep -iv login >> /var/
adm/syslog/sys_mon/imsi_syslog.txt
                        tail -$T_COUNT /var/adm/syslog/syslog.log | grep -i $KEY5 >> /var/adm/syslog/sys_mon/imsi_syslog.t
xt

                        M_COUNT=`cat /var/adm/syslog/sys_mon/imsi_syslog.txt | wc -l`

                        if [ $M_COUNT -gt 0 ];
                        then
                                /var/adm/syslog/sys_mon/chk_sms 'HLCDB2 syslog check!'
                                cat /dev/null > /var/adm/syslog/sys_mon/imsi_syslog.txt
                        fi
                        B_COUNT=$A_COUNT
                fi
        fi
done

728x90