Sponsored Content
Top Forums Shell Programming and Scripting Need help in a time-grep Script Post 302290372 by ali560045 on Monday 23rd of February 2009 05:16:04 AM
Old 02-23-2009
Need help in a time-grep Script

i have a script that will do the following:

1) find the 5 min before time from the current time
2) Grep the data from a file from current time to the 5 min before time

below the code:
Code:
#!/bin/ksh
current_time=`date +%s`
echo "$current_time"

perl -le 'print scalar localtime('$current_time');' | awk '{print $4}' | cut -c 1-5
a1=`perl -le 'print scalar localtime('$current_time');' | awk '{print $4}' | cut -c 1`
a2=`perl -le 'print scalar localtime('$current_time');' | awk '{print $4}' | cut -c 2`
a4=`perl -le 'print scalar localtime('$current_time');' | awk '{print $4}' | cut -c 4`
a5=`perl -le 'print scalar localtime('$current_time');' | awk '{print $4}' | cut -c 5`

echo "$a1" "$a2" "$a4" "$a5"

echo "Enter the seconds to be added"
read seconds1
echo "$seconds1"

sum=$(( $current_time - $seconds1 ))
echo "$sum"

perl -le 'print scalar localtime('$sum');' | awk '{print $4}' | cut -c 1-5
b1=`perl -le 'print scalar localtime('$sum');' | awk '{print $4}' | cut -c 1`
b2=`perl -le 'print scalar localtime('$sum');' | awk '{print $4}' | cut -c 2`
b4=`perl -le 'print scalar localtime('$sum');' | awk '{print $4}' | cut -c 4`
b5=`perl -le 'print scalar localtime('$sum');' | awk '{print $4}' | cut -c 5`

echo "$b1" "$b2" "$b4" "$b5"

output
Code:
1235383292
04:01
0 4 0 1
Enter the seconds to be added
300
300
1235382992
03:56
0 3 5 6



The problem here i m facing is how to grep the data from the file from time 03:56 to 04:01 ??

Below the file content:
Code:
Feb 20, 2009 12:59:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO: ---------------------------------------------------------------
Feb 20, 2009 03:56:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO: ---------------------------------------------------------------
Feb 20, 2009 03:57:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO:           authType=null
Feb 20, 2009 03:59:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO:      contentLength=-1
Feb 20, 2009 03:59:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO:        contentType=text/xml;charset=utf-8
Feb 20, 2009 04:00:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO:             header=Content-Type=text/xml;charset=utf-8
Feb 20, 2009 04:01:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO:             header=Transfer-Encoding=chunked
Feb 20, 2009 04:02:51 AM org.apache.catalina.valves.RequestDumperValve invoke


Last edited by ali560045; 02-23-2009 at 06:22 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep time and date

Hi, I have a file which is a result of a script running every two minutes. What I wanted to do is to grep a specific date and time (hour and minute) from the file and then count the occurance of 201. I need to get the result of occurance of 201 every 5 minutes. What should I include in my... (8 Replies)
Discussion started by: ayhanne
8 Replies

2. Shell Programming and Scripting

Grep two lines at a time

Hello; i have a log file which had Invalid, error, missing words in it. I want to grab a line which matches either of the above words and one more line below the grepped line. Can this be done? I looked on other places on your forum, but there is nothing which is working. I tried... (6 Replies)
Discussion started by: joshjimda
6 Replies

3. Shell Programming and Scripting

Grep for modified time

is it possible to come up with a list of files that are modified before a certain number of hours only using the grep command? ex. list files that were modified less than 10 hours ago i've only managed to list files that were created on the same day, i can't seem to figure out how to work... (3 Replies)
Discussion started by: momo.reina
3 Replies

4. Homework & Coursework Questions

Grep for modified time

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: is it possible to come up with a list of files that are modified before a certain number of hours only using the... (3 Replies)
Discussion started by: momo.reina
3 Replies

5. Shell Programming and Scripting

how to grep the time of the mail received?

Hi all, My question is how can we grep the time of the mail which we receive in our inbox? like if i get a mail tonight at 10 i should be able to grep the time of it tomorrow morning or someother day in 24 hr format.... how can we do that? (2 Replies)
Discussion started by: smarty86
2 Replies

6. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

7. Shell Programming and Scripting

grep the time within given minutes

Mar 26 15:25:11 : jdoe : TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - Mar 26 15:28:52 : jdoe : 3 incorrect password attempts ; TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - Mar 25 12:23:07 : jdoe : TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; ... (6 Replies)
Discussion started by: Daniel Gate
6 Replies

8. Shell Programming and Scripting

Ftp script hangs for first time,but works every second time

Hi I have an ftp script which works fine when i execute through a test scheduler(UC4), but when i run it through the prod scheduler(UC4), it hungs indefinetely, when we cancel the job and re-run it it works perfectly fine. here is the code,, any idea why this is happening ???? ... (1 Reply)
Discussion started by: selvankj
1 Replies

9. Shell Programming and Scripting

Time taken to run grep in different OS

Hi , I am greping a keyword in all sql files in Solaris and Linux. Solaris bash-3.00$ time grep -iwc BEN_STARTUP_LERS_TL084701_WHO *.sql Load__v20130719-prod.sql:0 Load__v20130719-prod.sql:0 Load__v20130719-prod.sql:0 Load__v20130719-prod.sql:0 Load__v20130719-prod.sql:0... (4 Replies)
Discussion started by: millan
4 Replies

10. UNIX for Dummies Questions & Answers

Grep with time constraints

Hello Friends - I am trying to grep certain messages that have a time slot like this: MyRate=33FC|SystemDEF=445DE|Calc=33W2|Time=15:50:24 I am trying to grep everything after Time=15:50:26 including SystemDEF=E2S and Calc=33W2 into a file called myrate.dat Not able to... (7 Replies)
Discussion started by: DallasT
7 Replies
time(1) 						      General Commands Manual							   time(1)

Name
       time - time a command

Syntax
       time command
       /bin/time command

Description
       The  command  lets  the specified command execute and then outputs the amount of elapsed real time, the time spent in the operating system,
       and the time spent in execution of the command.	Times are reported in seconds and are written to standard error.

       If you are using any shell except the C shell, you can give the command as shown on the first line of the Syntax section.  If you are using
       the  C shell, you must use the command's full pathname as shown on the second line of the Syntax section.  If you do not use the full path-
       name, will execute its own built-in command that supplies additional information and uses a different output format.

       The command can be used to cause a command to be timed no matter how much CPU time it takes.  For example:
       % /bin/time cp /etc/rc /usr/bill/rc
	       0.1 real 	0.0 user	 0.0 sys
       % /bin/time nroff sample1 > sample1.nroff
	       3.6 real 	2.4 user	 1.2 sys
       This example indicates that the command used negligible amounts of user and system time and had an elapsed time of 1/10 second (0.1).   The
       command used 2.4 seconds of user time and 1.2 seconds of system time, and required 3.6 seconds of elapsed time.

Restrictions
       Times are measured to an accuracy of 1/10 second.  Thus, the sum of the user and system times can be larger than the elapsed time.

See Also
       csh(1)

																	   time(1)
All times are GMT -4. The time now is 03:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy