need help with script

I have created a log file to attempt to alert myself if root or oracle directly logs into a server. I want to create a script that will check this log file every 30 minutes and if it finds one, send an alert. I can do everything but cannot figure out what combination of grep will work. My sticking point is with the hour and that I don't want more than one alert per hour.

root Fri Jul 6 10:58:34 2007
root Fri Jul 6 12:08:23 2007
root Fri Jul 6 12:08:25 2007
root Fri Jul 6 13:40:25 2007
root Fri Jul 6 14:09:57 2007
root Fri Jul 6 17:09:34 2007
root Fri Jul 6 18:03:10 2007
root Fri Jul 6 19:04:49 2007
root Fri Jul 6 19:04:57 2007
root Sat Jul 7 18:36:06 2007

Please help. I am ready to scream!

I am sure you are looking for more elegant solution but trying to see if I can do anything,

I guess obviously you can run this at top of the hour once and just increase the value for sleep time

but I am sure our forum gurus will come up something nice for u.. I am waiting to see so that I can learn as well!

#!/bin/bash
set +x
i=1
something=root

echo starting...

while [ "$i" -lt 3 ]   #(( $i < 3 )) 
    do
      I=`grep $something abc.log`
      echo trying to see if root has logged on this hour
      if [ -n "$I" ]
           then
              echo root has logged on
              exit 0
      elif [ "$i" -eq 1 ]
           then
             sleep 5
             echo sleeping for 5 sec
      fi
echo out of if loop
let i+=1
done
mLogFile='your_log_file'
set -- `egrep 'root' | tail -1 $mLogFile`
mLastMonth=$3
mLastDay=$4
mLastHour=`echo $5 | cut -f1 -d':'`
tail -1f $mLogFile | \
while read mCurr
do
  mRoot=`echo $mCurr | egrep -c 'root'`
  if [ "$mRoot" = "0" ]; then
    continue
  fi
  set -- $mCurr
  mCurrMonth=$3
  mCurrDay=$4
  mCurrHour=`echo $5 | cut -f1 -d':'`
  if [ "$mCurrMonth" != "$mLastMonth" -o  \
       "$mCurrDay"   != "$mLastDay"   -o  \
       "$mCurrHour"  != "$mLastHour" ]; then
    echo "Found new login: "$mCurr
  fi
  mLastMonth=$mCurrMonth
  mLastDay=$mCurrDay
  mLastHour=$mCurrHour
done

root@gs091# ./test.sh
mLogFile=/tmp/directoutput.txt
+ egrep root
+ tail -1 /tmp/directoutput.txt
mLastMonth=$3
mLastDay=$4
mLastHour=
tail: cannot open input
./test.sh: syntax error at line 4: `end of file' unexpected
+ set -- echo
+ [ = 0 ]
+ set --
mCurrMonth=
mCurrDay=
mCurrHour=
./test.sh: syntax error at line 6: `done' unexpected
root@gs091# + egrep -c rootecho

I added #!/bin/sh to the top of the file.

Any ideas?

Of hand, probably one error and possibly a transcription error.

mLogFile='your_log_file'
set -- `egrep 'root' $mLogFile | tail -1`
mLastMonth=$3
mLastDay=$4
mLastHour=`echo $5 | cut -f1 -d':'`
tail -1f $mLogFile | \   #make sure you don't have any spaces after the \
while read mCurr
do
  mRoot=`echo $mCurr | egrep -c 'root'`
  if [ "$mRoot" = "0" ]; then
    continue
  fi
  set -- $mCurr
  mCurrMonth=$3
  mCurrDay=$4
  mCurrHour=`echo $5 | cut -f1 -d':'`
  if [ "$mCurrMonth" != "$mLastMonth" -o  \
       "$mCurrDay"   != "$mLastDay"   -o  \
       "$mCurrHour"  != "$mLastHour" ]; then
    echo "Found new login: "$mCurr
  fi
  mLastMonth=$mCurrMonth
  mLastDay=$mCurrDay
  mLastHour=$mCurrHour
done

root@gs091# ./test.sh
mLogFile=/tmp/directoutput.txt
+ tail -1 /tmp/directoutput.txt
+ egrep root
+ set -- root Tue Jul 10 18:19:30 2007
mLastMonth=Jul
mLastDay=10
+ echo 18:19:30
+ cut -f1 -d:
mLastHour=18
+ tail -1f /tmp/directoutput.txt
+ read mCurr
+ echo root Tue Jul 10 18:19:30 2007
+ egrep -c root
mRoot=1
+ [ 1 = 0 ]
+ set -- root Tue Jul 10 18:19:30 2007
mCurrMonth=Jul
mCurrDay=10
+ echo 18:19:30
+ cut -f1 -d:
mCurrHour=18
+ [ Jul != Jul -o 10 != 10 -o 18 != 18 ]
+ read mCurr