#!/usr/bin/sh
#################################################################################
# Script Name : syslog_error_chk.sh #
# #
# Description : Searches for errors in syslog and mail . #
#################################################################################
LOG=/tmp/scsi_err.log
Se_file=/var/log/syslog/syslog.log
err1="error want to search"
err2="error want to search"
>$LOG
date +%Y"_"%b"_"%d"_"%H |awk -F '_' '{print $1,$2,$3,$4}'|while read cur_yr cur_mth cur_day cur_hr
do
srch_end_hr=0
srch_strt_hr=0
strt_day=0
srch_strt_mth=0
srch_strt_day=0
srch_string==0
if [ ${cur_hr} -lt 2 ]
then
#let srch_end_hr=${cur_hr}+1
#let srch_strt_hr=24+${cur_hr}-2
#let strt_day=${cur_day}-1
srch_end_hr=` echo "${cur_hr}+1"|bc `
srch_strt_hr=` echo "24+${cur_hr}-2"|bc `
strt_day=` echo "${cur_day}-1"|bc `
if [ ${strt_day} -eq 0 ]
then
case ${cur_mth} in
Jan) srch_strt_mth=Dec
srch_strt_day=31;;
Feb) srch_strt_mth=Jan
srch_strt_day=31;;
Mar) srch_strt_mth=Feb
leap_yr=` echo "${cur_yr}%4"|bc `
if [ "$leap_yr" -eq 0 ]
then
srch_strt_day=29
else
srch_strt_day=28
fi;;
Apr) srch_strt_mth=Mar
srch_strt_day=31;;
May) srch_strt_mth=Apr
srch_strt_day=30;;
Jun) srch_strt_mth=May
srch_strt_day=31;;
Jul) srch_strt_mth=Jun
srch_strt_day=30;;
Aug) srch_strt_mth=Jul
srch_strt_day=31;;
Sep) srch_strt_mth=Aug
srch_strt_day=31;;
Oct) srch_strt_mth=Sep
srch_strt_day=30;;
Nov) srch_strt_mth=Oct
srch_strt_day=31;;
Dec) srch_strt_mth=Nov
srch_strt_day=30;;
*) echo "Invaild Current Month" ;;
esac
else
#let srch_strt_day=${strt_day}
srch_strt_day=` echo ${strt_day} `
srch_strt_mth=` echo ${cur_mth} `
fi
if [ ${cur_hr} -eq 1 ]
then
egrep "${err1}|${err2}"" $Se_file|grep "${srch_strt_mth} ${srch_strt_day} 23" >>$LOG
egrep "${err1}|${err2}"" $Se_file|grep "${cur_mth} ${cur_day} 00" >>$LOG
egrep "${err1}|${err2}"" $Se_file|grep "${cur_mth} ${cur_day} 01" >>$LOG
else
egrep "${err1}|${err2}"" $Se_file|grep "${srch_strt_mth} ${srch_strt_day} 22" >>$LOG
egrep "${err1}|${err2}"" $Se_file|grep "${srch_strt_mth} ${srch_strt_day} 23">>$LOG
egrep "${err1}|${err2}"" $Se_file|grep "${cur_mth} ${cur_day} 00" >>$LOG
fi
else
#let srch_end_hr=${cur_hr}+1
srch_end_hr=` echo "${cur_hr}+1"|bc `
#let srch_strt_hr=${cur_hr}-7
srch_strt_hr=` echo "${cur_hr}-2"|bc `
#let srch_strt_day=${cur_day}
srch_strt_day=` echo "${cur_day}" `
srch_strt_mth=${cur_mth}
if [ ${srch_strt_hr} -lt 10 ]
then
srch_strt_hr=` echo "0${srch_strt_hr}" `
fi
if [ ${srch_end_hr} -lt 10 ]
then
srch_end_hr=` echo "0${srch_end_hr}" `
fi
while [ $srch_strt_hr -lt srch_end_hr ]
do
egrep "${err1}|${err2}" $Se_file|grep "${srch_strt_mth} ${srch_strt_day} ${srch_strt_hr}" >>$LOG
srch_strt_hr=`echo "${srch_strt_hr}+1"|bc`;
if [ ${srch_strt_hr} -lt 10 ]
then
srch_strt_hr=` echo "0${srch_strt_hr}" `
fi
done
fi
count=` cat $LOG|wc -l `
if [ ${count} -gt 0 ]
then
mailx -s "SCSI read and write errors from '$(hostname)'" xyz@gmail.com < $LOG
fi
done
No comments:
Post a Comment