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.
The following converts 2013-10-11 13:06:19 to seconds from epoch:
$ 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.
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.
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!!
If ksh93 is installed:
secs=$(printf "%(%s)T" "2013-10-11 13:06:39")
echo $secs
1381511199
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
Tested on ubuntu :
$ 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