The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 05:22 PM
Tail?? qfwfq Shell Programming and Scripting 7 06-19-2006 01:15 AM
how to sed with tail redlotus72 UNIX for Dummies Questions & Answers 1 08-30-2005 05:27 AM
using tail -f cdunavent Shell Programming and Scripting 6 10-23-2002 05:10 PM
Tail User bbutler3295 UNIX for Dummies Questions & Answers 7 03-21-2002 06:47 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-17-2006
jisc jisc is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 6
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?
  #2 (permalink)  
Old 05-18-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
something similar

You have something similar here
  #3 (permalink)  
Old 05-19-2006
jisc jisc is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 6
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?
  #4 (permalink)  
Old 05-19-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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-19-2006 at 02:08 AM..
  #5 (permalink)  
Old 05-19-2006
jisc jisc is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 6
thanks ranj, your script works, i appreciate your help
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0