Sponsored Content
Top Forums Shell Programming and Scripting Need help in a time-grep Script Post 302290403 by ali560045 on Monday 23rd of February 2009 07:10:30 AM
Old 02-23-2009
i m using the below logic using the awk command: but not getting the correct o/p when running the script:

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

perl -le 'print scalar localtime('$current_time');' | awk '{print $4}' | cut -c 1-5
echo "Enter the seconds to be subtracted"
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`

echo "$b1" "$b2" 
cd /ednadtu3/home/webapp/apache-tomcat-5.5.15/logs
awk '/[$b1-9][$b2-9]:[0-9][0-9]:/{c=2}c&&c--' sss.txt

output i m getting:
Code:
1235390785
06:06

Enter the seconds to be subtracted
7600
7600
1235383185
03:59
0 3 

Feb 20, 2009 12:59:51 AM org.apache.catalina.valves.RequestDumperValve invoke
INFO: ---------------------------------------------------------------

What i want:
Code:
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 08:15 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
SCRIPT(1)						    BSD General Commands Manual 						 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-a] [-f] [-q] [-t] [file] DESCRIPTION
Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Options: -a Append the output to file or typescript, retaining the prior contents. -f Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can super- vise real-time what is being done using `cat foo'. -q Be quiet. -t Output timeing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), replay(1). HISTORY
The script command appeared in 3.0BSD. BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. Linux July 30, 2000 Linux
All times are GMT -4. The time now is 09:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy