Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)
# 8  
Old 11-22-2013
Here is an approach using ksh93:
Code:
#!/bin/ksh93

while read user v1 v2 dt tm
do
   u_epoch_time=$( printf "%(%s)T" "${dt} ${tm}" )
   c_epoch_time=$( printf "%(%s)T" "now" )
   d_epoch_time=$(( $c_epoch_time - $u_epoch_time ))
   [ $d_epoch_time -gt 86400 ] && printf "%s User Checked out license for more than %.0f days\n" "$user" "$(( $d_epoch_time / 60 / 60 / 24 ))"
done < file.log

# 9  
Old 11-22-2013
If the date doesn't work right in mktime, I doubt it will work in GNU date either. I repeat:

Quote:
Originally Posted by Corona688
Check what the $4 " " $5 " 00" actually becomes? awk's mktime() expects "YYYY MM DD HH MM SS"
I think you can do
Code:
"date -d whatever" | getline

in awk if you really want to use GNU date but I think you need to fix the string first anyway.
# 10  
Old 11-28-2013
Corona688- I guess in the process of formatting date string to bring it to standard date format, I am doing something wrong. I noticed its changing field position number.
I haven’t tried to figure it out as Yoda’s suggested ksh93 script giving me the results what I am looking for. I will explore your second option about GNU date.
Thanks again for your help.

---------- Post updated at 06:11 PM ---------- Previous update was at 05:58 PM ----------

Yoda- Your script working like a charm. It took me foe while to figure out the error issue when I was executing the program by combine “bash” for awk and ksh93 date logic.
#!/bin/bash
#!/bin/ksh93
The above sequence was giving error, when ran with following sequence , its working.
#!/bin/ksh93
#!/bin/bash
Thank You!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a future date into epoch seconds on HPUX system

Hi All, I have scenario where i have to compare two dates. I thought of converting them to epoch seconds and do a numeric comparison. This works fine on Linux systems. $ date -d '2015/12/31' +%s 1451538000 $ date +%s 1449159121 But we don't have -d option in HPUX. What would be... (5 Replies)
Discussion started by: veeresh_15
5 Replies

2. Shell Programming and Scripting

Awk: time intervals based on epoch time

I have a list of epoch times delimited by "-" as follows: 1335078000 - 1335176700 1335340800 - 1335527400 1335771300 - 1335945600 1336201200 - 1336218000 The corresponding dates are: 20120422 1000 - 20120423 1325 20120425 1100 - 20120427 1450 20120430 1035 - 20120502 1100 ... (3 Replies)
Discussion started by: alex2005
3 Replies

3. Shell Programming and Scripting

Find time difference based on logfile

Hi All, Firstly thank you for the forum members I need to find time difference b'w two rows of timestamp using awk/shell. Here is the logfile: cat business_file start:skdjh:22:06:2010:10:30:22 sdfnskjoeirg wregn'wergnoeirnfqoeitgherg end:siifneworigo:22:06:2010:10:45:34... (3 Replies)
Discussion started by: Srinivas Gadi
3 Replies

4. Shell Programming and Scripting

Current triggered time to epoch seconds

I have a requirement to find long running instances for notifying the stake holders based on the triggered time in AIX. I am not sure how to convert the triggered time to epoch seconds. For example : Current triggered time of instance is 13:06:19 -> how to convert this into epoch in the... (5 Replies)
Discussion started by: chandu123
5 Replies

5. Shell Programming and Scripting

Adding Seconds to UNIX/Epoch-Time

Hello All, I have a Perl script I'm writing where I ask the user to enter a "start time" for something. The "$start_time" will be in the format of: # The Time CLI Option Can be in the format of: --start-time="1day" --start-time="2hours" --start-time="45min" ... (1 Reply)
Discussion started by: mrm5102
1 Replies

6. Shell Programming and Scripting

Based on the first & last timestamp of the file, need to calculate the time taken to complete

Below is the sample file: 287 DEBUG syndesis.pb.util.ITraceManager - syOID=ELntNetwork:1005Mon Oct 15 17:18:21 IST 2012 <ELClientManagerenEmsSession() > Setting Java Properties 287 DEBUG syndesis.pb.util.ITraceManager - syOID=ELntNetwork:1005Mon Oct 15 17:18:21 IST 2012... (1 Reply)
Discussion started by: ashok.kumar
1 Replies

7. Shell Programming and Scripting

Transpose timestamp based on column values and calculate time difference

Hello Expert, I need to transpose Date-Timestamp based on same column values and calculate time difference. The input file would be as below and required output is mentioned in the bottom INPUT File ======== 08/23/2012 12:36:09 JOB_5340 08/23/2012 12:36:14 JOB_5340 08/23/2012... (2 Replies)
Discussion started by: asnandhakumar
2 Replies

8. Shell Programming and Scripting

Date conversion from Standard/given format to seconds/epoch

I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates. Example : date -d "2007-09-01 17:30:40" '+%s' But this gives me below error date: illegal option -- d Usage: date OS: AIX... (6 Replies)
Discussion started by: bpaac
6 Replies

9. Programming

How to search a file based on a time stamp backwards 10 seconds

Hi all, I'm after some help with this small issue which i'm struggling to work out a fix for. I have a file that contains records that all have a time stamp for each individual record, i need to search the file for a specific time stamp and then search back 10 seconds to see if the number... (2 Replies)
Discussion started by: sp3arsy
2 Replies

10. Shell Programming and Scripting

conversion from EPOCH timestamp to local time zone

hello gurus, i want a perl/shell script which once invoked should convert a set of EPOCH timestamps to local time ( IST..i want) . how does it work ,i have an idea on that..but writing a perl/shell script for it is not possible for me...so i need help for the same. my exact requirement is... (2 Replies)
Discussion started by: abhijeetkul
2 Replies
Login or Register to Ask a Question