scan log file by a search string
|
Original Message
|
Name: pretty21
Date: June 8, 2008 at 22:38:13 Pacific
Subject: scan log file by a search stringOS: unixCPU/Ram: 2gbModel/Manufacturer: solaris |
Comment: 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
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Curt R
Date: June 11, 2008 at 12:50:36 Pacific
Subject: scan log file by a search string |
Reply: (edit)***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 Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Curt R
Date: June 11, 2008 at 12:56:34 Pacific
Subject: scan log file by a search string |
Reply: (edit)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 Offensive Follow Up For Removal
|
Use following form to reply to current message: