![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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? |
|
||||
|
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
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
|
|
||||
|
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.. |
|
||||
|
thanks ranj, your script works, i appreciate your help
![]() |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|