Monitoring & emailing log files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Monitoring & emailing log files
# 8  
Old 02-14-2008
Tools If the log might still be open...

# see if the file exists
if [ -e full.log ]
then
# check the number of lines
cur_log_line=$(cat full.log | wc -l)
# compare to entry in saved file
lst_log_line=$(cat lst_log_line_file)
if [ cur_log_line -gt lst_log_line ]
then
# get lines after the last pass-thru
tail_lines = cur_log_line - lst_log_line
tail -$tail_line full.log > today.log
# set the last line checked
echo $cur_log_line > lst_log_line_file
# mail the file
uuencode today.log today.log | mailx -s "logs" somebody@me.com
fi
fi

p.s. funny how this board removes leading spaces - the code was more readable when indented

Last edited by joeyg; 02-14-2008 at 02:37 PM.. Reason: added p.s.
# 9  
Old 02-14-2008
On Solaris 10 you can use the "logadm" utility to make any file rotate.

So configure logadm is such a way that a specific file is rotated at fixed times.

Suppose the name of this file is X.
After rotation the name of this file will be X.0 and there will be a new empty file X.

Create cron job which executes a few minutes after rotation of the log file has taken place, and which verifies the file X.0 for the presence of the messages you are interested in and takes the necessary actions e.g. emailing the result.
# 10  
Old 02-14-2008
That's very close

Thanks all for the help.
The particular log file is an Oracle log file for a particular process they do.
I'll give this a try and post any questions here. Thanks again!
# 11  
Old 02-14-2008
One more thing

I want to check the file for a particular line of text between checks. I was going to have a cron job rerun periodically and only check any new additions to the file. I can't mv the file as Oracle keeps it open.

That's probably the last piece of the puzzle. Thanks all!
# 12  
Old 02-14-2008
mv /var/tmp/copy1 /var/tmp/copy2 2> /dev/null
cp <oracle log file> /var/tmp/copy1

diff /var/tmp/copy1 /var/tmp/copy2 | grep -v ^[0-9] | sed -e "s/^[<>] //" | grep <search string>
 
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