Current triggered time to epoch seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Current triggered time to epoch seconds
# 1  
Old 10-11-2013
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 shellscript. Please help.
# 2  
Old 10-11-2013
The following converts 2013-10-11 13:06:19 to seconds from epoch:

Code:
$ perl -MTime::Local -e 'print timelocal(19, 6, 13, 11, 9, 2013)'
1381476979

The month is from 0..11 (Jan..Dec) and so, Oct is 9.
These 2 Users Gave Thanks to balajesuri For This Post:
# 3  
Old 10-11-2013
Thank you for the response. I am looking for something in a shell rather than perl as we do not have perl installed in all the aix servers. Also, can you post a small snippet of code where my output of the triggered time comes in hh:mm:ss format and to append current date and then conver to epoch seconds , that will be really helpful.


Code:
eg:

Output of my instance -> 13:06:39
Need to append today's date -> 2013-10-11
then : Convert to epoch seconds ->Want to capture this result.

Help is really appreciated. Thank you!!
# 4  
Old 10-12-2013
If ksh93 is installed:
Code:
secs=$(printf "%(%s)T"   "2013-10-11 13:06:39")
echo $secs
1381511199

# 5  
Old 10-12-2013
Quote:
Originally Posted by chandu123
I am looking for something in a shell rather than perl as we do not have perl installed in all the aix servers.
Strange! It's quite surprising that a *nix system is being shipped without perl! I did a quick search and found this link that mentions "Perl is included by default in AIX.

You could check if perl is installed by typing these commands:
which perl or [ICODE]perl --version[/ICODE
# 6  
Old 10-12-2013
Tested on ubuntu :

Code:
$ date -u -d "$(date '+%Y-%m-%d') 13:06:39" +%s
1381583199
$ date -u -d @1381583199 +%Y-%m-%d" "%T
2013-10-12 13:06:39

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. UNIX for Dummies Questions & Answers

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

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

4. Red Hat

How to check that a particular value is epoch seconds?

how to verify that the following is epoch time. that is if i have given some random value like 34600 , how can i know it is epoch seconds (5 Replies)
Discussion started by: ramsavi
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

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

7. 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

8. Shell Programming and Scripting

Get Current Time in Seconds Perl

hi guys, i need to know how to get the current date/time in seconds and i want to be able to do this in a one liner. like say for instance, if want to get what the time is right now, i'll issue a command like this: ## perl -e ' print scalar(localtime(time + 0)), "\n"' Tue Jul 13 17:45:50... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Dummies Questions & Answers

getting the current time in Epoch format

Hi everybody, I want to get the current time in epoch format (in UNIX or Korn Shell) and store it in a variable called currentTime. Any response will be highly appreciated:) Thanks in advance, omoyne:D (8 Replies)
Discussion started by: omoyne
8 Replies

10. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies
Login or Register to Ask a Question