Stop append to file after 5 minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stop append to file after 5 minutes
# 1  
Old 03-02-2010
Stop append to file after 5 minutes

Hi all,

I've got a grep command, in which the value (a number) is being appended into a file. Such file will have this output:

Code:
100
105
300
204
150
...
...
120
113
124

This file will continue to append, since the grep line runs every 10 seconds. Is there a way to stop the file after 5 minutes, take the largest value (input it into another file) and restart again?

rgds,

Matthew

Last edited by Scott; 03-02-2010 at 06:13 PM.. Reason: Code tags
# 2  
Old 03-02-2010
Tools

Sounds like your grep command is part of another script, and that is where a lot of this requested programming would probably need to originate.
Please show that script.
# 3  
Old 03-02-2010
Thanks for your reply, Here it is. it basically greps from the text file and make a word count.

Code:
#!/bin/csh -f
grep -v CPC IsupStatusDump.txt | grep "," | grep 4148 | grep IcConversation | awk '{print$11}' | sort | wc -l >> 4148inc2.txt
endif

Thanks

Last edited by Scott; 03-02-2010 at 06:13 PM.. Reason: Code tags please...
# 4  
Old 03-02-2010
this stops and restarts a local shell function.
anything more complicated gets tough in shell script

Code:
#!/bin/bash

trap 'kill $!' EXIT

doit()
{
    while sleep 1;do
    date
    done
}
doit&

pid=$!
sleep 5
kill -STOP $pid
echo press enter
read x
kill -CONT $pid
sleep 5

# 5  
Old 03-02-2010
Tools The following is just written in pseudo-code

Code:
#setting to keep running forever
keep_running = 1
while (keep_running = 1)
  do
  count=1
# do 60 times, at 5 second delay equals 5 minute total run
  while (count <=60)
    do
    grep file1 blah-blah-blah >>file2
# sleep for 5 seconds
    sleep 5
    count=count+1
  done

#file3 is where you store your max values
  sort file2 | tail -1 >>file3
#start a new file2
  rm file2
done

Again, only the 'logic' and not the actual coding. An approach to solve what you were asking. (I think?!)
# 6  
Old 03-03-2010
thanks guys, i will try them out and check. Thanks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Length of video file in minutes

I need to extract the length of a video file in minutes, not seconds or hours. How do I get the amount of minutes exclusively? (2 Replies)
Discussion started by: locoroco
2 Replies

2. UNIX for Beginners Questions & Answers

rsync a file as it gets created and after 3 minutes old

- run a backup job - The jobs creates partial files one after the other, about 2 minutes interval. What i want to do is that while the job is still running or while a file was last modified or created 3 minutes ago, the file should be rsync to a remote server untill the last file has been... (4 Replies)
Discussion started by: malaika
4 Replies

3. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

4. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

5. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

6. Shell Programming and Scripting

Need help in getting the Last 30 minutes logs from the Log File

I have a log file with the below contents : log_file_updated.txt : Jul 5 03:33:06 rsyslogd: was Jul 5 03:33:09 adcsdb1 rhsmd: This system is registered. Sep 2 02:45:48 adcsdb1 UDSAgent: 2015-07-05 04:24:48.959 INFO Worker_Thread_4032813936 Accepted connection from host <unknown>... (3 Replies)
Discussion started by: rahul2662
3 Replies

7. Shell Programming and Scripting

Log File Creations for every 60 minutes

Hi All, Below script will make a copy of the existing log file with the then timestamp details. I am looking to create a copy of the existing log file for every 60 minutes and when the file limit reaches to 5, the 6th copy should overwrite the first backedup file which means all the time it... (3 Replies)
Discussion started by: Upendra Bestha
3 Replies

8. Shell Programming and Scripting

Find the age of a file in Minutes

KSH: Please lt me know how to find the age of a file in minutes(Based on last modified time). ie, if the file was modified 15 Minutes ago, the output should be 15 (1 Reply)
Discussion started by: hari_anj
1 Replies

9. Shell Programming and Scripting

Grepping the last 30 minutes of a log file...

I need to know if anyone can assist me on how to grab the last (we'll just say "x" minutes) of a log file. How do you tell the grep command without specifying an exact window of time? (So relative instead of absolute.) Thanks, Jon (2 Replies)
Discussion started by: jtelep
2 Replies

10. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies
Login or Register to Ask a Question