[PLUG] Another grep question

Russell Evans russell-evans at uswest.net
Sun Aug 3 14:40:03 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
  MONTH=`$DATE_BIN +%b`
  DAY=`$DATE_BIN +%e`
  DATESTR="$MONTH $DAY"
  if [ $DAY -gt 9 ] ; then
    DATE_TEST=`$NTP_BIN -uq $TIME_SERVER | tail -n1 | awk '{print $2,$1}'`
  else
    DATE_TEST=`$NTP_BIN -uq $TIME_SERVER | tail -n1 | awk '{print $2," "$1}'`
  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
  DATESTR="$MONTH $DAY"
  MONTH=`$DATE_BIN +%b`
  DAY=`$DATE_BIN +%e`
  DATESTR="$MONTH $DAY" 
fi

if [ $1 ] ; then
  if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
    echo "usage $0 [ pattern ]"
    echo "Searh $LOG for today's date and pattern if supplied"
    exit 0
  fi
  SEARCH=$DATESTR.*$1
  echo "$SEARCH"
  grep -h -e "$SEARCH" $LOG || exit 1
else
  echo here
  grep -h "$DATESTR" $LOG || exit 1
fi

exit 0


Thank you
Russell



On Sun, 3 Aug 2003 11:59:16 -0700 (PDT), Steven Raymond said:

> Okay, now that I got "echo" to stop stripping out my wanted spaces, how do
>  I pass the output of it to grep, surrounded by quotes?  The following is
>  broke because grep sees:
>  
>  DATESTR=`date -d "today" '+%b %e'`
>  grep `echo "$DATESTR"` /var/log/maillog
>  
>  
>  grep Aug  3 /var/log/maillog
>  
>  Grep doesn't like the space(s) between Aug and 3.  I have tried all sorts
>  of single- and double-quoting around the echo command, but it gets broken
>  in various ways.  Any easy fixes?
>  
>  Perhaps I should explain my end goal instead of bugging plug every 15
>  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.
>  
>  
>  
>  
>  
>  _______________________________________________
>  PLUG mailing list
>  PLUG at lists.pdxlinux.org
>  http://lists.pdxlinux.org/mailman/listinfo/plug
>  
>  





More information about the PLUG mailing list