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
Data::Random(3pm)					User Contributed Perl Documentation					 Data::Random(3pm)

NAME
Data::Random - Perl module to generate random data SYNOPSIS
use Data::Random qw(:all); my @random_words = rand_words( size => 10 ); my @random_chars = rand_chars( set => 'all', min => 5, max => 8 ); my @random_set = rand_set( set => @set, size => 5 ); my $random_enum = rand_enum( set => @set ); my $random_date = rand_date(); my $random_time = rand_time(); my $random_datetime = rand_datetime(); open(FILE, ">rand_image.png") or die $!; binmode(FILE); print FILE rand_image( bgcolor => [0, 0, 0] ); close(FILE); DESCRIPTION
A module used to generate random data. Useful mostly for test programs. METHODS
rand_words() This returns a list of random words given a wordlist. See below for possible parameters. o wordlist - the path to the wordlist file. On Debian systems one can be found at /usr/share/dict/words. You can also optionally supply a Data::Random::WordList object to keep a persistent wordlist. The default is the wordlist distributed with this module. o min - the minimum number of words to return. The default is 1. o max - the maximum number of words to return. The default is 1. o size - the number of words to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to. o shuffle - whether or not the words should be randomly shuffled. Set this to 0 if you don't want the words shuffled. The default is 1. Random::Data::WordList returns words in the order that they're viewed in the word list file, so shuffling will make sure that the results are a little more random. rand_chars() This returns a list of random characters given a set of characters. See below for possible parameters. o set - the set of characters to be used. This value can be either a reference to an array of strings, or one of the following: alpha - alphabetic characters: a-z, A-Z upperalpha - upper case alphabetic characters: A-Z loweralpha - lower case alphabetic characters: a-z numeric - numeric characters: 0-9 alphanumeric - alphanumeric characters: a-z, A-Z, 0-9 char - non-alphanumeric characters: # ~ ! @ $ % ^ & * ( ) _ + = - { } | : " < > ? / . ' ; ] [ ` all - all of the above o min - the minimum number of characters to return. The default is 0. o max - the maximum number of characters to return. The default is the size of the set. o size - the number of characters to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to. o shuffle - whether or not the characters should be randomly shuffled. Set this to 0 if you want the characters to stay in the order received. The default is 1. rand_set() This returns a random set of elements given an initial set. See below for possible parameters. o set - the set of strings to be used. This should be a reference to an array of strings. o min - the minimum number of strings to return. The default is 0. o max - the maximum number of strings to return. The default is the size of the set. o size - the number of strings to return. The default is 1. If you supply a value for 'size', then 'min' and 'max' aren't paid attention to. o shuffle - whether or not the strings should be randomly shuffled. Set this to 0 if you want the strings to stay in the order received. The default is 1. rand_enum() This returns a random element given an initial set. See below for possible parameters. o set - the set of strings to be used. This should be a reference to an array of strings. rand_date() This returns a random date in the form "YYYY-MM-DD". 2-digit years are not currently supported. Efforts are made to make sure you're returned a truly valid date - ie, you'll never be returned the date February 31st. See the options below to find out how to control the date range. Here are a few examples: # returns a date somewhere in between the current date, and one year from the current date $date = rand_date(); # returns a date somewhere in between September 21, 1978 and September 21, 1979 $date = rand_date( min => '1978-9-21' ); # returns a date somewhere in between September 21, 1978 and the current date $date = rand_date( min => '1978-9-21', max => 'now' ); # returns a date somewhere in between the current date and September 21, 2008 $date = rand_date( min => 'now', max => '2008-9-21' ); See below for possible parameters. o min - the minimum date to be returned. It should be in the form "YYYY-MM-DD" or you can alternatively use the string "now" to represent the current date. The default is the current date; o max - the maximum date to be returned. It should be in the form "YYYY-MM-DD" or you can alternatively use the string "now" to represent the current date. The default is one year from the minimum date; rand_time() This returns a random time in the form "HH:MM:SS". 24 hour times are supported. See the options below to find out how to control the time range. Here are a few examples: # returns a random 24-hr time (between 00:00:00 and 23:59:59) $time = rand_time(); # returns a time somewhere in between 04:00:00 and the end of the day $time = rand_time( min => '4:0:0' ); # returns a time somewhere in between 8:00:00 and the current time (if it's after 8:00) $time = rand_time( min => '12:00:00', max => 'now' ); # returns a date somewhere in between the current time and the end of the day $time = rand_time( min => 'now' ); See below for possible parameters. o min - the minimum time to be returned. It should be in the form "HH:MM:SS" or you can alternatively use the string "now" to represent the current time. The default is 00:00:00; o max - the maximum time to be returned. It should be in the form "HH:MM:SS" or you can alternatively use the string "now" to represent the current time. The default is 23:59:59; rand_datetime() This returns a random date and time in the form "YYYY-MM-DD HH:MM:SS". See the options below to find out how to control the date/time range. Here are a few examples: # returns a date somewhere in between the current date/time, and one year from the current date/time $datetime = rand_datetime(); # returns a date somewhere in between 4:00 September 21, 1978 and 4:00 September 21, 1979 $datetime = rand_datetime( min => '1978-9-21 4:0:0' ); # returns a date somewhere in between 4:00 September 21, 1978 and the current date $datetime = rand_datetime( min => '1978-9-21 4:0:0', max => 'now' ); # returns a date somewhere in between the current date/time and the end of the day September 21, 2008 $datetime = rand_datetime( min => 'now', max => '2008-9-21 23:59:59' ); See below for possible parameters. o min - the minimum date/time to be returned. It should be in the form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string "now" to represent the current date/time. The default is the current date/time; o max - the maximum date/time to be returned. It should be in the form "YYYY-MM-DD HH:MM:SS" or you can alternatively use the string "now" to represent the current date/time. The default is one year from the minimum date/time; rand_image() This returns a random image. Currently only PNG images are supported. See below for possible parameters. o minwidth - the minimum width of the image. The default is 1. o maxwidth - the maximum width of the image. The default is 100. o width - the width of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to. o minheight - the minimum height of the image. The default is 1. o maxheight - the maximum height of the image. The default is 100. o height - the height of the image. If you supply a value for 'width', then 'minwidth' and 'maxwidth' aren't paid attention to. o minpixels - the minimum number of random pixels to display on the image. The default is 0. o maxpixels - the maximum number of random pixels to display on the image. The default is width * height. o pixels - the number of random pixels to display on the image. If you supply a value for 'pixels', then 'minpixels' and 'maxpixels' aren't paid attention to. o bgcolor - the background color of the image. The value must be a reference to an RGB array where each element is an integer between 0 and 255 (eg. [ 55, 120, 255 ]). o fgcolor - the foreground color of the image. The value must be a reference to an RGB array where each element is an integer between 0 and 255 (eg. [ 55, 120, 255 ]). VERSION
0.07 AUTHOR
Originally written by: Adekunle Olonoh Currently maintained by: Buddy Burden (barefoot@cpan.org), starting with version 0.06 CREDITS
Hiroki Chalfant David Sarno COPYRIGHT
Copyright (c) 2000-2011 Adekunle Olonoh. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Data::Random::WordList perl v5.14.2 2012-06-04 Data::Random(3pm)
All times are GMT -4. The time now is 04:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy