Script to monitor log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to monitor log file
# 1  
Old 03-24-2012
Script to monitor log file

Hi,

Have written a script to monitor linux non standard log file based on line numbers, so each check store $otalinenum ..

then in next check after 10 minutes it compre the current_total_line_num > last_total_line_num then it will parse the log file from last_total_line_num to current_total_line_num with sed as below
Code:
if [ $current_total_line_num -gt $last_total_line_num ]
then
  sed -n ''$oldln','$totl'p;'$totl'q' log-file | grep -i shirish
else 
  grep -i shirish log-file
fi

But here am facing problem if someone truncate the log file or delete some lines from them .. insted normal log rotation then my script parse the entire log file ((with else above)) insted from new updates ..

Please help me with logic to avoid old log alerts when file truncate happen ...
Code:
# cat -n log-file
1 a1 shirish abc anf 
2 a2 shukla anf 
3 a3 shirish anf fd

## After truncate
Code:
# cat -n log-file
1 a1 shirish abc anf 
2 a3 shirish anf fd


--Shirish Shukla

Last edited by Franklin52; 03-24-2012 at 12:30 PM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I add a log file path to a vi file to monitor all the changes made to the file?

I'm curious to know how do I add an empty log file (test1.log) to an existing text file to monitor all the changes made to a.txt. Is this expression export PATH=$PATH:/home/test1.log right to be added to the text file a.txt? (5 Replies)
Discussion started by: TestKing
5 Replies

2. Shell Programming and Scripting

Script to monitor /var/log/messages

Hello All, I want to write a script to monitor my product logs from /var/log/messages and send notifications without using "tail -f" command.Please suggest alternatives and any other tools for monitoring and alerting. Thank You (1 Reply)
Discussion started by: Cva2568
1 Replies

3. Shell Programming and Scripting

Monitor log file

Hi, I need to amend an existing ksh script so that it runs a process (stop weblogic) and in parallel needs to monitor a log file (startup.log) in the background for a certain string (e.g. unable to stop weblogic). If the string appears in the log i need to kill the stop weblogic process. ... (5 Replies)
Discussion started by: dholmaster
5 Replies

4. HP-UX

Script to monitor /var/opt/resmon/log/event.log file

AM in need of some plugin/script that can monitor HP-UX file "/var/opt/resmon/log/event.log" . Have written a scrip in sh shell that is working fine for syslog.log and mail.log as having standard format, have interrogated that to Nagios and is working as I required . But same script failed to... (3 Replies)
Discussion started by: Shirishlnx
3 Replies

5. Shell Programming and Scripting

Continiously monitor the log file

Hi Friends, I am trying to write a script which continiously monitor one specific error message from a log file. This script should continiously monitor the file for the error and send out the email when detect the error message. I tried the below command but fails. Please help me. tail -f... (4 Replies)
Discussion started by: arumon
4 Replies

6. Shell Programming and Scripting

Monitor dynamic log file for a particular Error

Hi Folks, I need help in creating a script to monitor a continuously updating log for one particular error. If the the script finds the error it should send out an email. Thanks for all ur help (2 Replies)
Discussion started by: a12ka4
2 Replies

7. Shell Programming and Scripting

Need help for this monitor log script

this is the format of the log file in my system xxxxx_xxx_xxxx_xxxxx_09_10_2009_170457.log xxxx_xxx_2_0_09_10_2009_163834.log xxx_xxxxxxxxx_25_10_2009_045020.log xxx_xxxxxxx_08_11_2009_055728.log the path of this logs file in on for example /dellxmax/application/log what i want to do... (5 Replies)
Discussion started by: coxmanchester
5 Replies

8. Shell Programming and Scripting

Script to monitor the pattern in the log file

hi All, how to find a pattern in the log file & display the above and below line for example in the log file, i have many lines, whenever i search for "Category" it should display the above line with only few parameter like i want only the location name & department name Thu Jul 02 11:05:23... (2 Replies)
Discussion started by: rithick256
2 Replies

9. UNIX for Dummies Questions & Answers

Log monitor script

Hi All, I have a question and hope someone will have an answer to that. I'm looking for a way to monitor log files being generated on a windows machine for some specified string and if its occurrence is found, raise an alarm though email. The log file size keeps on increasing and after a... (2 Replies)
Discussion started by: er_ashu
2 Replies

10. Shell Programming and Scripting

Bash tail monitor log file

Hi there, I have a problem here that involves bash script since I was noob in that field. Recently, I have to monitor data involve in logs so I just run command tail -f for the monitoring. The logs was generate every hour so I need to quickly change my logs every time the new hour hits according... (2 Replies)
Discussion started by: kriezo
2 Replies
Login or Register to Ask a Question