Script to grep log files based on system date
I would like help to write a script to grep a log file and count the no of lines based on a string and/or system date and mail the result.
For ex Mon May 4 04:10:09 2009 ---x-x-x-x- Mon May 4 15:44:27 2009 x-x-x--x-xx--x Mon May 4 15:45:35 2009 xx=xxx-x-x--xx Mon May 4 22:53:43 2009 xxx-x-x--x-xx Tue May 5 07:27:18 2009 xxxx Tue May 5 04:12:58 2009 abcd In this log file i should be able grep no of lines for system date ( ex for May 5 its 2 and for may 4 its 4) also if possible grep no of lines for a string within the results of the first query by(date) and mail the result. for example for May 5 no of lines for string abcd will be 1. Help in advance is appreciated. Thanks Mohammed |
So your first stop would be 'man grep' for a basic understanding of what grep can do, then 'man date' for a basic understanding of how to get it to output your datestamp format. Then on to http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html and http://www.tldp.org/LDP/Bash-Beginne...tml/index.html. If you can post back the date string command and what switches grep uses to anchor a searchterm and count lines you're half way through. Good luck!
|
cron mails automatically as does at
also one can do something like this: (pipe output to mail) your_script | mailx -vs subject user or if you want to be clever you can embed commands in the mail like: Code:
mailx -vs subject user <<EOF I'lll leave the grep to you. |
All times are GMT -5. The time now is 11:45 PM. |