[PLUG] Another grep question
Russell Evans
russell-evans at uswest.net
Sun Aug 3 18:21:02 UTC 2003
#!/bin/sh
LOG=/var/log/maillog
TIME_SERVER=128.118.46.3
DATE_BIN=`which date 2>/dev/null`
NTP_BIN=`which ntpdate 2>/dev/null`
if [ ! -r $LOG ] ; then
echo "$LOG is not readable"
exit 1
fi
if [ $NTP_BIN ] && [ $DATE_BIN ] ; then
LOCAL_DATE=`$DATE_BIN +%b%e || exit 3`
MONTH=${LOCAL_DATE::3}
PREDAY=${LOCAL_DATE:3:3}
DAY=${PREDAY// }
if [ $DAY -gt 9 ] ; then
DATE_TEST=`$NTP_BIN -uq $TIME_SERVER | tail -n1 | awk '{print $2,$1}' ||
exit 4`
DATESTR="$MONTH $DAY"
else
DATE_TEST=`$NTP_BIN -uq $TIME_SERVER | tail -n1 | awk '{print $2," "$1}' ||
exit 4`
DATESTR="$MONTH $DAY"
fi
if [ "$DATESTR" != "$DATE_TEST" ] && [ "$DATE_TEST" ] ; then
echo "System date is "$DATESTR" while $TIME_SERVER has date $DATE_TEST"
exit 2
fi
elif [ $DATE_BIN ] ; then
LOCAL_DATE=`$DATE_BIN +%b%e || exit 3`
MONTH=${LOCAL_DATE::3}
PREDAY=${LOCAL_DATE:3:3}
DAY=${PREDAY// }
if [ $DAY -gt 9 ] ; then
DATESTR="$MONTH $DAY"
else
DATESTR="$MONTH $DAY"
fi
fi
case $1 in
-h | --help )
echo "usage $0 [ pattern ]"
echo "Searh $LOG for today's date and pattern if supplied"
exit 0
;;
*)
SEARCH=$DATESTR.*$1
grep -h -e "$SEARCH" $LOG || exit 2
;;
esac
exit 0
I got to spend a little more time on this. This is kind of useful to me, hence
my interest, but I what to add getopts so that I can switch log files and do
other things better, i.e. I might want to search for -h or --help someday.
Thank you
Russell.
On Sun, 3 Aug 2003 11:59:16 -0700 (PDT), Steven Raymond said:
> minutes when I run into a new problem. I simply want to make a daily (or
> perhaps every 4 hours) cron job that emails me the output of every line of
> my /var/log/maillog* which contains the word "reject" so I can keep track
> of spams (for alerting me to false positives). Plus I get a small thrill
> just seeing how many spams are correctly rejected. There must be a
> smarter way to do so than my current scripting efforts which have thus far
> been a shameful embarrasment. ;) Advice is appreciated.
More information about the PLUG
mailing list