Monitoring & emailing log files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Monitoring & emailing log files
# 1  
Old 11-28-2007
Monitoring & emailing log files

Hi
..first post !

I have a Unix v445 using solaris 10. I've trolled through various web pages but can't find exactly what I'm looking for.

I have an alert log...or any messages file for that matter I need to check for certain key (error type) phrases - if I find them, they are redirected to a file and emailed to a distribution list. I want to execute this script as a cron job running every hour.

The next time the cron job runs, rather than running from the top again & thus possibly duplicating the same errors, I need a seperate file that shows the linecount from the previous check.....this new check starts its checking from the linecount to the end of the file......the new line count replaces the previous one and so on

Do I need to have a 'collector' that holds the words/phrases I'm looking for ?
_________________

Can anyone help ?

Many thanks

David
# 2  
Old 11-28-2007
It sounds like the algorithm is pretty clear in your head.
Yes you need to write a collector/parse that would have 2 parameters:
  1. path to the log file to parse
  2. path to the file that holds the last known line number examined/parsed by the parser
The parser you read the 'line number' from the 'line number' file and start its parsing of the log file from the next line.
Once the entire file is parsed and the 'offending' records/lines are collected (most likely in another file), the parser will email the collected entries/files to the configured (either in the configuration file OR specified on the command line) list of the email address(es).
Once the emailing is done, the parser will update the 'line number' file with the number of the LAST parsed line in the file.

You should probably make provisions to make sure that there's only ONCE instance of the parser running at the time in order to avoid any collisions.

Now it's a matter of a simple programming....
# 3  
Old 11-29-2007
Thanks for the update.

Does anyone have similar code examples I can use to progress

Thanks

David
# 4  
Old 11-29-2007
Me always going the easy route, I would do this:
Check for errors in the log file, and then move that log file off to a new name. Then the next time around you would just grep the log file again, no need to keep up where you left off. This would work unless others need that log file and wouldn't be able to go look at your backup's.
# 5  
Old 02-14-2008
Looking to do the same thing

Davidra, did you ever get an answer for this or samples of script? I'm trying to do the same exact thing for a non-syslog log file.
# 6  
Old 02-14-2008
Tools Just writing pseudo-code...

Is the following the logic flow you desire?

# see if the file exists
if [ -e today.log ]
then
# mail the file
uuencode today.log today.log | mailx -s "logs" somebody@me.com
# append the today.log to the rest of the log file
cat today.log >> all.log
# delete the working log file
rm today.log
fi
# 7  
Old 02-14-2008
gotchas

Be careful rm'ing or mv'ing log files. If the app that is writting them keeps the file open, you may not get the results you expect. The app could continue writing to the inode of the file and your new file won't be touched.

What I do is keep a running tail on the log and alert when a condition is met. There are utilities out there (logwatch comes to mind) that will save you lots of work.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Solaris 10 & 11 ZFS Space Monitoring

Hi Folks! Its been a while since I worked with ZFS but basically, I need to monitor free space for Solaris 10 & 11 systems (with & without zones) I am hoping that any space commands only need to be run from the global zone (to simplify matters) However, I'm not not sure if there are exceptions... (2 Replies)
Discussion started by: GazinLincoln
2 Replies

2. Shell Programming and Scripting

Crontab 2>&1 not emailing

I have a script that emails me when I run it manually, but the crontab I'm using must be 'silencing' the output? Here's what I have: */15 * * * * /usr/src/blah.sh > /dev/null 2>&1 I don't want it to email me every time it runs, just when I run the sendmail command inside the script if the... (13 Replies)
Discussion started by: unclecameron
13 Replies

3. Shell Programming and Scripting

CLI script for emailing alert if files missing in dir

thread removed (4 Replies)
Discussion started by: billabongjimmy
4 Replies

4. UNIX and Linux Applications

SAP & DB2 Process Monitoring Parameters

What are the parameters ((i.e., Process & Services) need to monitor for SAP & DB2 to capture shutdown, restart & Halt status of those applications. Please suggest the best practices. Ex: SAPSTART for SAP & DP2SYS for DB2 (3 Replies)
Discussion started by: marunmeera
3 Replies

5. Solaris

Monitoring log file for entries - Find command & sorting

hi, I would like to monitor a log file, which rolls over, everytime a server is restarted. I would like to grep for a string, and to be more efficient i'd like to grep only newly appended data. so something like a 'tail -f' would do, however, as the log rolls over i think a 'tail -F' is... (2 Replies)
Discussion started by: horhif
2 Replies

6. Shell Programming and Scripting

Need to count files & create log of that.

Hi Friends, I need some help. First look at my files hierchachy /<level-1>/<level-2>/<level-3>/*.tif eg. : /2010-07-01/AFFIDAVIT-OF-SERVICE---FOR-SC/001/Babylon2_20100701012049_1278004849.49892_000.tif... (2 Replies)
Discussion started by: paragnehete
2 Replies

7. Shell Programming and Scripting

Monitoring specific string or keyword in rotating log files.

Hi there, I like to ask how i shall monitor specific string or keyword in rotating log files. e.g. I have at 10 rotating logfiles. I use the command below to grep the string, but eventually become non functional because the logfile rotates and new logfile is active. tail -f <logfile1> |grep... (1 Reply)
Discussion started by: shtobias
1 Replies

8. Shell Programming and Scripting

Copying files and emailing them out

Hello everybody, I'm trying to create a script that will cd into a directory and then copy the file with yesterday's date on it and then cd into another directory doing the same thing. Afterwards, i'm trying to zip up the two files, and email them out to people. Can anyone help? thanks a... (1 Reply)
Discussion started by: jhofilena
1 Replies

9. UNIX for Advanced & Expert Users

AFP & FTP Bandwidth Monitoring?

Is there a way to monitor FTP and AFP bandwidth on a per user basis? AFP = AppleFilesharingProtocol, and by monitor, I don't mean graphs, I mean getting raw byte counts I can use in my scripts any way I choose. I am attempting to use mod_watch to monitor virtual domain bandwidth usage, but I really... (0 Replies)
Discussion started by: l008com
0 Replies

10. Shell Programming and Scripting

Perl - Emailing MULTIPLE files as attachment

Hi Guys, I would love an example as to how I can send multiple files in one email using perl. The file types are .csv I have read that mimencode is required? Is there any other way or is that it? Thanks :) (3 Replies)
Discussion started by: Tonka52
3 Replies
Login or Register to Ask a Question