Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Processing a log file based on date/time input and the date/time on the log file

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-15-2008
primp primp is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 22 December 2008, 11:35 PM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 03-15-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 5 May 2017, 7:24 AM EDT
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
Here you can probably find something useful:

http://www.unix.com/answers-frequent...rithmetic.html

Regards
Sponsored Links
    #3  
Old Unix and Linux 03-16-2008
primp primp is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 22 December 2008, 11:35 PM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
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?
    #4  
Old Unix and Linux 03-16-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 5 May 2017, 7:24 AM EDT
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 03-16-2008
primp primp is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 22 December 2008, 11:35 PM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search on date range of file based on user input lostincashe Shell Programming and Scripting 5 03-30-2012 03:03 PM
Convert Epoch time format to normal date time format in the same file rk4k Shell Programming and Scripting 3 11-19-2008 09:04 PM
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 09:23 PM
how do I put a date and time in a file name jhamm UNIX for Dummies Questions & Answers 2 01-16-2007 08:31 AM



All times are GMT -4. The time now is 07:31 PM.