The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to extract date with time from file prash_b Shell Programming and Scripting 5 06-18-2008 05:30 AM
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 06:23 PM
how do I put a date and time in a file name jhamm UNIX for Dummies Questions & Answers 2 01-16-2007 05:31 AM
file creation date & time alisevA3 UNIX for Dummies Questions & Answers 3 07-08-2005 02:21 AM
File date and time stamp Xenon UNIX for Dummies Questions & Answers 1 10-09-2001 12:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-15-2008
Registered User
 

Join Date: Mar 2008
Posts: 19
Stumble this Post!
Processing a log file based on date/time input and the date/time on the log file

Hi,

I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work

I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is associated when the file is created.

application.log.1
application.log.2
application.log.3
application.log.4
application.log.5

I have another script that will take an input of date/time, I'm not sure which is the easiest format to compare, from the short look around it sounds like epoch is the easiest/fastest.

I would like to take that format whichever it is, and basically subtract 5minutes which is a poll period thats been defined and then use that date/time to compare with the logs that are rotated and basically process the log that closely matches the "currentInputDateTime" where it can not be larger than "currentInputDateTime" but less than/equal to the current time, I assume this might be a "ls -tr | awk '{print $6 $7}' to get the date/time and somehow convert those to epoch.

I was wondering if this was something that has been encountered before so the wheel does not have to be re-invented.

Thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-15-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,961
Stumble this Post!
Here you can probably find something useful:

Yesterdays Date/Date Arithmetic

Regards
Reply With Quote
  #3 (permalink)  
Old 03-15-2008
Registered User
 

Join Date: Mar 2008
Posts: 19
Stumble this Post!
I was taking a look at those links and I saw that you could pass in a parameter such as the following:

date -d "2008-03-15 11:40" --date="5 minutes ago" +%F==%I:%M

Though the output was:

2008-03-15==09:30

I was expecting to get back 11:35 for the time, is there something I'm missing to take a date format and subtract 5minutes from that time and convert it to epoch time to compare with other epoch values?
Reply With Quote
  #4 (permalink)  
Old 03-16-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,961
Stumble this Post!
It should be something like:

Code:
date --date "2008-03-15 11:40 5 min ago" +%F==%I:%M
But what is the reason for using this format "+%F==%I:%M"?
You can get the epoch time of 5 minutes ago with:

Code:
date --date "2008-03-15 11:40 5 min ago" +%s
Regards
Reply With Quote
  #5 (permalink)  
Old 03-16-2008
Registered User
 

Join Date: Mar 2008
Posts: 19
Stumble this Post!
Thank you, I was going down that route of using the "5 minutes ago" but didn't realize it was support to be part of the input string, that was where I got confused on and I did not couldn't find an example online or was not reading the man pages correctly. I'll try what you've provided with my script to see if I can get this working
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0