Help on scripting using tail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on scripting using tail
# 1  
Old 05-18-2006
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  
Old 05-18-2006
something similar

You have something similar here
# 3  
Old 05-19-2006
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  
Old 05-19-2006
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 03:08 AM..
# 5  
Old 05-19-2006
thanks ranj, your script works, i appreciate your help Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tail +

because the tail +2 on the first line gives me the file name pomga I do not want anything like what I miss tail +2 ejemplo.txt ouput ==> ejemplo.txt <== 1 2 3 4 5 6 7 8 9 10 (2 Replies)
Discussion started by: tricampeon81
2 Replies

2. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

3. Shell Programming and Scripting

tail out of memory

Hi, I am performing a tail command on EBCDIC coded files and am getting the following error message when I try to process very large files. tail: There is not enough memory available now. The file in question has more than 10 millions lines. I would like to ask for advice for... (4 Replies)
Discussion started by: Indalecio
4 Replies

4. Shell Programming and Scripting

tail -f monitoring

Is there any file on UNIX that changes periodically so that I could use tail -f command to watch changes? I was searching a long time and I didn't find nothing (I'm newbie to UNIX so it's not a surprise to me though) Thanks for help :) (6 Replies)
Discussion started by: MartyIX
6 Replies

5. Shell Programming and Scripting

tail -f

I am trying to extract a particular line from a.log which keeps appending every sec and output that into a newfile b.log which should append itself with filtered data received from a.log I tried tail -f a.log |grep fail| tee -a b.log nothing in b.log tail -f a.log |grep fail >>b.log ... (4 Replies)
Discussion started by: wannalearn
4 Replies

6. Shell Programming and Scripting

Tail??

Hello all, I have search the forum and could not find an answer...Here is what I am trying to do. Every 15 minutes, a script send uptime output to a logfile (dailylog.log), that file contains lines like the one below: 11:21am up 44 days, 19:15, 1 user, load average: 0.00, 0.02, 0.03 ... (7 Replies)
Discussion started by: qfwfq
7 Replies

7. Shell Programming and Scripting

tail command..

I was wondering how can I do this I have file myfile.txt wc -l is: 5 000 000 I have to remove first 1 000 000 lines from header.. I tryed with tail -4000000 myfile.txt>newfile.txt but it does not work... any help?? (2 Replies)
Discussion started by: amon
2 Replies

8. Shell Programming and Scripting

using tail -f

Working in HP-UX 10.20. I eventually want to write a bourne shell script to handle the following problem, but for now I am just toying with it at the command line. Here's what I am basically trying to do: tail -f log_X | grep n > log_Y I am doing a tail -f on log_X . Once it sees "n", I... (6 Replies)
Discussion started by: cdunavent
6 Replies

9. Shell Programming and Scripting

How to terminate a tail -f

I am developing a script with a tail -f in it. My problem is how to terminate it and execute the next line. (4 Replies)
Discussion started by: DonVince
4 Replies

10. UNIX for Dummies Questions & Answers

Tail User

Ok i looked through quite a few posts but could not find what i was looking for so forgive me if this post can be found elese where... I would like to use a command like tail view what users are doing in the system i have quite a few dba's that come come to my office and do work on the system... (7 Replies)
Discussion started by: bbutler3295
7 Replies
Login or Register to Ask a Question