Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- General
- >
- Re: Grep lines from a log based on time specific i...
General
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-04-2008 02:41 PM
12-04-2008 02:41 PM
Grep lines from a log based on time specific in minutes
Hi,
I am writing a korn shell script to calculate average response times from a weblogic log. I need to grep lines based on time in minutes specified by a user and display the average time. For e.g. if a user specifies 30 mins, I need to grep transaction lines from the log in the last 30 mins and calculate the average times from that.
Will I be able to do that kind of date/time calculation from a ksh scipt? Also in the logs, this is the timestamp format for the weblogic transactions: 2008.12.04 13:51:15:106 PST. How can I convert back and forth if I use epoch seconds to do this calculation? I can use perl for this but the requirement is do it from a ksh script which I am not very comfortable with. Any help is greatly appreciated. Thanks.
I am writing a korn shell script to calculate average response times from a weblogic log. I need to grep lines based on time in minutes specified by a user and display the average time. For e.g. if a user specifies 30 mins, I need to grep transaction lines from the log in the last 30 mins and calculate the average times from that.
Will I be able to do that kind of date/time calculation from a ksh scipt? Also in the logs, this is the timestamp format for the weblogic transactions: 2008.12.04 13:51:15:106 PST. How can I convert back and forth if I use epoch seconds to do this calculation? I can use perl for this but the requirement is do it from a ksh script which I am not very comfortable with. Any help is greatly appreciated. Thanks.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-04-2008 03:14 PM
12-04-2008 03:14 PM
Re: Grep lines from a log based on time specific in minutes
Hi:
> How can I convert back and forth if I use epoch seconds to do this calculation? I can use perl for this but the requirement is do it from a ksh script which I am not very comfortable with.
You can write your Korn shell script as you want. Simply use Perl to do the work of converting the log's timestamps into epoch seconds. Look for log records that lie in the epoch second-based range.
For example:
...
E=$(./make_epoch "2008.12.04 13:51:15")
echo ${E}
1228431720
Your current time is given simply from:
C=$(perl -le 'print time')
1228431725
Regards!
...JRF...
> How can I convert back and forth if I use epoch seconds to do this calculation? I can use perl for this but the requirement is do it from a ksh script which I am not very comfortable with.
You can write your Korn shell script as you want. Simply use Perl to do the work of converting the log's timestamps into epoch seconds. Look for log records that lie in the epoch second-based range.
For example:
...
E=$(./make_epoch "2008.12.04 13:51:15")
echo ${E}
1228431720
Your current time is given simply from:
C=$(perl -le 'print time')
1228431725
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-04-2008 03:29 PM
12-04-2008 03:29 PM
Re: Grep lines from a log based on time specific in minutes
Thanks James. The machine they script is going to be run on doesn't have perl installed, thats why I wanted to find out if I could do it purely in ksh. I will get them to install perl on the machine so it makes everybody's life easier :). Appreciate your help! Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-04-2008 06:08 PM
12-04-2008 06:08 PM
Re: Grep lines from a log based on time specific in minutes
Hi (again):
I'm losing it...I forgot to insert the Perl script I'm suggesting:
# cat ./make_epoch
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $date = shift or die "Timestamp expected\n";
my $fmt = qr{(\d+)\.(\d+)\.(\d+)\s(\d+):(\d+):(\d+)};
die "Wrong format; 'yyyy.mm.dd hh:mm:ss' expected\n" unless $date =~ $fmt;
my ( $yyyy, $mm, $dd, $hrs, $min, $sec ) = ( $date =~ $fmt );
my $epoch = timelocal( $sec, $min, $hrs, $dd, $mm - 1, $yyyy );
print "$epoch\n";
1;
Regards!
...JRF...
I'm losing it...I forgot to insert the Perl script I'm suggesting:
# cat ./make_epoch
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $date = shift or die "Timestamp expected\n";
my $fmt = qr{(\d+)\.(\d+)\.(\d+)\s(\d+):(\d+):(\d+)};
die "Wrong format; 'yyyy.mm.dd hh:mm:ss' expected\n" unless $date =~ $fmt;
my ( $yyyy, $mm, $dd, $hrs, $min, $sec ) = ( $date =~ $fmt );
my $epoch = timelocal( $sec, $min, $hrs, $dd, $mm - 1, $yyyy );
print "$epoch\n";
1;
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP