Operating System - HP-UX
1827313 Members
4922 Online
109961 Solutions
New Discussion

search syslog for errors with perl

 
SOLVED
Go to solution
simon peter
Occasional Contributor

search syslog for errors with perl

Hi
I have a perl script which searches syslog for error message.In this case i have just used "vmunix" but what i want to be able to do is only list error's for set date.

For example if i run script now it will only check for messages in the last 24 hours.

Regards
Simon
1 REPLY 1
Chris Vail
Honored Contributor
Solution

Re: search syslog for errors with perl

Here's one I wrote:
This requires 2 additional files, one of which is a "filter" file, and the other a list of email addys.
#!/bin/ksh
# Loganalyzer
# July 2002 by C. Vail

# Analyze system logs and email the results
# Arguments to the grep -v command should be placed in
# $FFILE. These is a simple text file with one argument per line.

IAM=`uname -n`
PPATH=/root/work/logs # Path to this file
LPATH=/var/adm/syslog # Path to the log file
MFILE=$PPATH/loganalyzer.mail # List of email addys
FFILE=$PPATH/loganalyzer.filters # Filter file
LFILE=$LPATH/syslog.log # Log file name
TFILE=$PPATH/loganalyzer.tmp # Temporary files
UFILE=$PPATH/loganalyzer.tmp2

if test -f $TFILE
then
rm $TFILE
fi

# This script is designed to run a minute after midnight each day.
# Hence, we need yesterday's date. This gets tricky because of
# end of month and year considerations.
TMONTH=`date -u +%m`
TDAY=`date -u +%d`

if test "$TDAY" = "01"
then
case $TMONTH in
01) MONTH=Dec;YSDAY=31;;
02) MONTH=Jan;YSDAY=31;;
03) MONTH=Feb;YSDAY=28;;
04) MONTH=Mar;YSDAY=31;;
05) MONTH=Apr;YSDAY=30;;
06) MONTH=May;YSDAY=31;;
07) MONTH=Jun;YSDAY=30;;
08) MONTH=Jul;YSDAY=31;;
09) MONTH=Aug;YSDAY=31;;
10) MONTH=Sep;YSDAY=30;;
11) MONTH=Oct;YSDAY=31;;
12) MONTH=Nov;YSDAY=30;;
esac
else
YSDAY=`echo "$TDAY - 1"|bc`
MONTH=`date -u +%b`
fi

case $YSDAY in
1) DAY=" 1";;
2) DAY=" 2";;
3) DAY=" 3";;
4) DAY=" 4";;
5) DAY=" 5";;
6) DAY=" 6";;
7) DAY=" 7";;
8) DAY=" 8";;
9) DAY=" 9";;
*) DAY=$YSDAY
esac

grep "$MONTH $DAY" $LFILE>$TFILE

NUM1=`wc -l $TFILE|awk '{ print $1 }'`

for FILTER in `cat $FFILE`
do
cat $TFILE|grep -v $FILTER>$UFILE
mv $UFILE $TFILE
done

pr -n -t $TFILE>$UFILE
mv $UFILE $TFILE


NUM2=`wc -l $TFILE|awk '{ print $1 }'`
NUM3=`echo "$NUM1 - $NUM2"|bc`


echo "Total Lines: $NUM1 Filtered: $NUM3">>$TFILE

for ADDY in `cat $MFILE`
do
cat $TFILE|mailx -s "{SYSLOG} $IAM" Logs for $MONTH $DAY" $ADDY
done