Need Suggestion, on how to constantly moniter a file and display content with in that time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Suggestion, on how to constantly moniter a file and display content with in that time
# 1  
Old 12-18-2013
Need Suggestion, on how to constantly moniter a file and display content with in that time

Dear Gurus,

I'm in a strange situation, hence need some kind of advice or possible syntax to carry on.

let's say
Code:
current time/date is 2013-12-18, 15:58:15

I got a file something like this, which keep getting updated with respect to time.

Code:
2013-12-18, 15:56:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 15:57:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 15:58:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 15:59:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 14:15:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 14:23:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736

So, now I will run the script then it should sum the duration in my file from (current time - 5mins)
hence it should sum

Code:
2013-12-18, 15:56:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 15:57:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 15:58:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736
2013-12-18, 15:59:15,[http-3],USERNAME,SUCCESS,DURATION,815,EXECUTE,CELLS,1736

so every time if it runs then that moment it will go to file and subtract 5 mins from the current system time and only display sum of duration falling this time range(i.e. with in system date and system date - 5mins).

I would like to make in UNIX scripting.
# 2  
Old 12-18-2013
Specify your OS
Code:
uname -a

# 3  
Old 12-18-2013
sorry it is GNU/Linux, 2.6.32.59-0.7-default
# 4  
Old 12-18-2013
Using ksh93 printf %T formatting option:
Code:
#!/bin/ksh93

c_ts=$( printf "%(%s)T" "now" )

while IFS=, read dt tm skip
do
        f_ts=$( printf "%(%s)T" "${dt} ${tm}" )
        d_ts=$(( $c_ts - $f_ts ))
        [ $d_ts -le 300 ] && print "${dt},${tm},${skip}"
done < file

# 5  
Old 12-19-2013
Thanks at the moment it's working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moniter files and merge

Hi All, I have a requirement where I need to monitor the files in a directory for 15 secs and if the size of the files are not changing within that time I would like to merge all the data in those files and move it to another directory with a time stamp For eg dir1 I have 10 files and... (2 Replies)
Discussion started by: Tomlight
2 Replies

2. Shell Programming and Scripting

Long list file display different time format.

Hi Gurus, I have some weird issue. when using ls -l the result shows different time format: -rw-r--r-- 1 abc gourp1 3032605576 Jun 14 2013 abc -rw-rw-r-- 1 abc gourp1 1689948832 Aug 10 06:22 abc one display 2013 which is year; another one displays 06:22 which is time. ... (4 Replies)
Discussion started by: ken6503
4 Replies

3. Shell Programming and Scripting

Grep to display file name along with content in Solaris

Am using the following grep to match a particular patter in grep. grep xyz abc.txt now while i run this command, if the pattern matched, am getting the line containing xyz Output: xyz is doing some work Now if i want the file name also along with my output, what should i do Expected... (2 Replies)
Discussion started by: rituparna_gupta
2 Replies

4. Shell Programming and Scripting

Display specific lines content from the file

Hell, I want to grep certain word from file and display above 2 lines and after two lines. Here is the content of sample file. Mar 14, 2013 12:56:59 AM Agent.Agent SendTo INFO: Connection to server:7041 - Credential Transmit Successesful Mar 14, 2013 8:54:21 AM cgent SendTo WARNING:... (7 Replies)
Discussion started by: balareddy
7 Replies

5. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

6. UNIX for Dummies Questions & Answers

Display the content of the unix file

cat is the normal unix command to display the content of a file. Is there any program to display the content of the file. If there is, then can you send me the code. (5 Replies)
Discussion started by: vedanjalig
5 Replies

7. UNIX for Dummies Questions & Answers

Display message on screen and flat file at same time

Hi guys, I have a script that call another, the other displays de message and I can print directly to the flat file, but in one command I am searchig that this message can be displayed in the screen and in the flat file in one command. I am doing something like this: var=$(./Example.sh)... (2 Replies)
Discussion started by: pipoca
2 Replies

8. Shell Programming and Scripting

Pattern matching in file and then display 10 lines above every time

hiii, i have to write a shell script like this---- i have a huge log file name abc.log .i have to search for a pattern name "pattern",it may occur 1000 times in the log file,every time it finds the pattern it should display the 10 lines above the pattern. I appericiate your help. (30 Replies)
Discussion started by: namishtiwari
30 Replies

9. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies

10. Shell Programming and Scripting

file display on screen on pg at time

hi can some body please help me...i'm been sitting here trying to figure how to do this..but still don't understand. Like each type of *.src (if any) in the given directory will be displayed on the screen one page at a time.... can someone explain how to do this..plz (1 Reply)
Discussion started by: zip_zip
1 Replies
Login or Register to Ask a Question