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.
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