Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
scan log file by a search string
Name: pretty21 Date: June 8, 2008 at 22:38:13 Pacific OS: unix CPU/Ram: 2gb Product: 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.
Name: Curt R Date: June 11, 2008 at 12:50:36 Pacific
Reply:
***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.
0
Response Number 2
Name: Curt R Date: June 11, 2008 at 12:56:34 Pacific
Reply:
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.
Summary: I am look for a shell script to scan all files in the system to find out if a file contains a particular string. If yes, then write the file name, path and line number containing the searching string ...
Summary: Hi there, I have a program which will write some log information to a log file. The problem is this log file grows too fast. But the log information is necessary to me. What I want to do is trying to ...
Summary: Hi, I'm having problem writing to a log file. Appreciate if anyone can help. I'm running an application thru a script ("A") with input and output file as /opt/bin/appl $OUTPUT_FILE & from there I ca...