The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tail -f wannalearn Shell Programming and Scripting 4 04-10-2007 02:22 PM
Tail?? qfwfq Shell Programming and Scripting 7 06-18-2006 10:15 PM
how to sed with tail redlotus72 UNIX for Dummies Questions & Answers 1 08-30-2005 02:27 AM
using tail -f cdunavent Shell Programming and Scripting 6 10-23-2002 02:10 PM
Tail User bbutler3295 UNIX for Dummies Questions & Answers 7 03-21-2002 02:47 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-17-2006
Registered User
 

Join Date: Mar 2006
Posts: 6
Stumble this Post!
Help on scripting using tail

Hi, just need help here, i have this command that i need to run all through out the day, basically this will just monitor a logfile and print a line if theres an error.

tail -f L*|grep "PROCESS IS DEAD"

this will echo a line "*** PROCESS IS DEAD: RW [Signal w/ Core dump: 10] ***" whenever a program logs a dead process error.

what i need is to add a command that will execute every time a line is grep. can someone here help me out.

maybe its something that looks like this but i dont know the syntax.

tail -f L*|grep "PROCESS IS DEAD" -exec mailx "BLAH BLAH" {} \;

can someone help me?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-17-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
Stumble this Post!
something similar

You have something similar here
Reply With Quote
  #3 (permalink)  
Old 05-18-2006
Registered User
 

Join Date: Mar 2006
Posts: 6
Stumble this Post!
thanks for the link ranj

Code:
#! /bin/ksh
curr_date = `date "+%m.%d"`
file=/datamart/logs/LOG.`date "+%m.%d"`

tail -f $file |&
while read -p err_line; 
do [[ $err_line = "*** PROCESS IS DEAD: RW [Signal w/ Core dump: 10] ***" ]] && {
  echo "mailx scripts goes here"
 }
done
i know too litlle of scripting so i'd like to ask if you guys can help me debug this code. the code above works, because the whole is specified, but i just want a pattern match not an absolute match of the line so i'd like to change it to "*PROCESS IS DEAD*" but its not working. can you help me out on this? how does pattern matching work on scripting?

and one more important thing, i'd like to add as you can see my log file name is LOG.MM.DD where MM is month and DD is day. How can I add a code in the script to make the tail command stop and start again on 12:05am (when log file name will change). basically i was thinking of changing the while part to while read -p err_line && curr_date = `date "+%m.%d"` and then put the whole code to a loop.

so i was thinkng of changing the script from that above to this:

Code:
#! /bin/ksh
do
curr_date = `date "+%m.%d"`
file=/datamart/logs/LOG.`date "+%m.%d"`
tail -f $file |&
while read -p err_line && curr_date = `date "+%m.%d"`; 
do [[ $err_line = "*PROCESS IS DEAD*" ]] && {
  echo "mailx scripts goes here"
 }
done
done
but its not working, can you guys help me correct this?
Reply With Quote
  #4 (permalink)  
Old 05-18-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
Stumble this Post!
Try like this!! Not sure if it is efficient.

while read -p err_line
do
echo $err_line | grep "pattern" && echo "mailx scripts goes here"
done


For the change of timestamp in the logfile, you could check for the time in this loop and exit it after 00:00 and then start the loop again. See if this works for you.
You can catch the pid of the background job and kill it before you reassign the logfile name,But make sure you have lot of error check into the script. I did it below like this.
while true #the main loop
do
tail -f $logfile |&
while read -p line
do
job_id=$! #get the background job process id

echo $line | grep "pattern" && echo "mailx scripts go here"

if [[ `date +%H` -lt 1 -a `date +%M` -gt 5 ]]; then #check for your time
break; #break out from loop
fi
done

kill $job_id #kill the id

sleep 5 # wait for sometime for the kill to complete its action.

logfile="$LOG/May_19.log" #reassign logfile
done

Last edited by ranj@chn; 05-18-2006 at 11:08 PM.
Reply With Quote
  #5 (permalink)  
Old 05-19-2006
Registered User
 

Join Date: Mar 2006
Posts: 6
Stumble this Post!
thanks ranj, your script works, i appreciate your help
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0