Can we run tail -f for a specified time?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can we run tail -f for a specified time?
# 1  
Old 09-21-2011
Can we run tail -f for a specified time?

Hi all,

I want to check a log file that gets updated very frequently, almost every second. What I want to do from a script is to check this log file
1) for a particular string
2) for a specified time
while it is getting updated. And as soon as it finds that particular string the command should stop.
I got the information from this forum which will satisfy the need 1)
but now I am looking how can a specify time for which the log file should be checked.

Originally Posted by Annihilannic
Try:
Code:
Code:
tail -f $VAULogFile | awk '/Phase/;/Phase 2 ended/ { exit }'

No need for a kill, the tail should terminate automatically when the pipe is closed.

Above is the code I used to check the log file for a particular string and exit when it is found. But now I want to specify time for which the log file should be checked and if the string is not found in the specified time then tail stop. Is it possible?

Thanks.
# 2  
Old 09-21-2011
Try:
Code:
tail -f $VAULogFile | awk '/Phase/;/Phase 2 ended/ { exit }' &
sleep time_in_secs
kill %1

# 3  
Old 09-21-2011
If you're on Linux:

Code:
timeout 30 tail -f $VAULogFile | awk '/Phase/;/Phase 2 ended/ { exit }'

If not:

Code:
tail -f $VAULogFile | awk '/Phase/;/Phase 2 ended/ { exit }' &
PID=$!

DIEAT=`expr $SECONDS + 30`
while [ -d /proc/$PID ] && [ "$SECONDS" -lt "$DIEAT" ]
do
        sleep 1
done

[ -d /proc/$PID ] && kill "$PID"
wait

# 4  
Old 02-21-2012
Thank you bartus11 and Corona688. It helped me. And sorry for responding so late....
# 5  
Old 02-21-2012
Better late than never. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i use tail & grep in real time here??

Hi I have a file which is updated very frequently. Where in i wanted to use tail -f command in the script and wanted to grep for a particular word. But the issue is when i use tail -f filename|grep "word" ... it will show me blank until the word is found in the real time. if it shows... (13 Replies)
Discussion started by: nikhil jain
13 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

How to tail real time file Generated every hour?

Hi Guys, I am developing a script to monitor log file Generated every hour. When creating a new file scripts not working. My Code . I want to monitor GatewayTransaction.yyyymmdd-hh.log while true; do newdate=$(date '+%Y%m%d') ; nowdate=$(date '+%Y%m%d-%H.log'); tail -f... (7 Replies)
Discussion started by: ooilinlove
7 Replies

4. Shell Programming and Scripting

how to run tail -f for 3 log files from a script

hi i need to run from a bash script tail -f /var/log/access_log >> access1 tail -f /var/log/prod/prod1 >> access1 tail -f /var/log/prod/prod2 >> access1 this script purpose is to start at server boot time and should always run. what is the best way to put it on a script Thanks Dan (1 Reply)
Discussion started by: dan12341234
1 Replies

5. Shell Programming and Scripting

How to tail -f real time file.

How to tail -f real time file. I want to tail file created last time. The server is gen new file Always. . An example file. -rw-r--r-- 1 shinnie tiituck 251M Oct 18 05:39 20111018_00.log -rw-r--r-- 1 shinnie tiituck 251M Oct 18 11:18 20111018_01.log -rw-r--r-- 1 shinnie tiituck... (3 Replies)
Discussion started by: ooilinlove
3 Replies

6. Programming

Run time Debugging

We have recently downloaded, installed and compiled gcc-3.0.4 code. gcc compiler has built successfully and we where able to compile some same test cpp file. I would like to know how we can modify gcc source code so that we add additional run time debugging statements like the binary in execution... (4 Replies)
Discussion started by: uunniixx
4 Replies

7. Shell Programming and Scripting

Show date/time with tail|grep command

Hi, I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time: tail -F catalina.out | sed "s/^/`date `/" | egrep ... (6 Replies)
Discussion started by: julugu
6 Replies

8. Shell Programming and Scripting

last run time of any script

how to find when last time a scrit has ran? (7 Replies)
Discussion started by: RahulJoshi
7 Replies

9. Shell Programming and Scripting

Run several commands at a time

Hello guys, I am new at shell scripting and I want to create a script that runs several commands at a time, ie: uptime, w, df -h and so on and send the output of this commands to a text file so it can be send via email at a certain time using crontab. Any help will be much appreciated! (4 Replies)
Discussion started by: agasamapetilon
4 Replies

10. Shell Programming and Scripting

Run script at same time

Hi My five script run throgh crontab at same time at 6 clock. Due to problem in the data load .Now I want to check time of load finish run these jobs. I create a script which check the load finish time but I have no idea how I run these JObs. This is very urget to me. Please reply me as soon... (3 Replies)
Discussion started by: Jamil Qadir
3 Replies
Login or Register to Ask a Question