scan log file by a search string

June 8, 2008 at 22:38:13
Specs: unix, 2gb
Hi, need your help please. I want to scan our daily log file (its increasing daily) for the Error message encountered.

After scanning, if ERROR is found, it will send email alert.

Thanks in advance



See More: scan log file by a search string

Report •


#1
June 11, 2008 at 12:50:36
***Begin Script***

#!/bin/ksh

#delete file created by the grep command (start fresh)
rm /path/filename
#error checking
if [ $# -eq 0 ]
then
echo "Usage is: $0 logfile error_message"
exit 1
elif [ $# -gt 2 ]
then
echo "Usage is: $0 logfile error_message"
exit 1
else
#perform scan for error message, put error message in #text file if found
grep "$2" "$1" > /path/filename
fi
#send "alert" email to admin if error msg found
#or send "No errors" email if none found
if [ -s "/usr/home/curtr/test2" ]
then
mail -s "Error Alert!" admin@domain.net < /path/filename
else
echo "No Errors" | mail -s "No Errors in Log file" admin@domain.net
fi
exit 0

***End Script***

Where:
path = path to file created by the script
filename = the name of the file created by script
admin@domain.net = your (valid) email address

I tested this and it works on my OpenBSD system.


Report •

#2
June 11, 2008 at 12:56:34
Forgot to add, this should accept a file in another folder as input but to be sure, test it.

If not, you'll want to run this from the directory the log file is located in and have the " grep "$2" "$1" > /path/filename" create the file in the same folder (as the script and log file) as well.


Report •

Related Solutions


Ask Question