Time in seconds on AIX 4.3.2.0

Hi to everybody
again i Need your help, i wasting hours but can't find a solutuin for my Problem. I am not an expert with AIX script programming.
I have a csh script and i need the time in seconds but since i have an old AIX the Option -%s doesnot exist with the date command. I seach in Google but what i found was most use perl --- ok next Problem i don't know perl and how can i use perl commands inside my csh script , or is there any easy way to get time time in my script ?

Thanks in advance

You can try my general purpose date script which is a GNU-date-alike written in Perl, which ought to support %s. It can also do date math.

To use it, put it in a text file and set it executable, you should be able to run it. You may need to adjust the path of #!/usr/bin/perl to wherever perl happens to be on your system.

2 Likes

Hi Corona688,

thanks a lot for the link to your great date script. but i just looking for a one line command inside the csh Shell which can transfer the value of time() to a varieable in the script. Your code offer many different Options which i don't neednow , your Program are bigger than my script .
Mabe you have a solution for me to get seconds from perl time() into a variable in my csh script

Thanks a lot for your support

try this to get epoch time:

nawk 'BEGIN {srand();time=srand();print time}' </dev/null
1 Like

Wouldn't this suffice:

awk 'BEGIN {print srand()}'
1487859688

?

2 Likes

If i remember AIX 4.3.2 correctly (sorry, but is been a long time) there should be the "%T" option which displays the (24h-)time in the format "HH:MM:SS".

Check this with the man page of date i have no way of accessing man pages for this (probably pre-2000) version.

I hope this helps.

bakunin

1 Like
perl -e 'print time(), "\n";'
1 Like

Thanks to all of you for your fast Response

1.) code from Vgersh99 it works perfect

nawk 'BEGIN {srand();time=srand();print time}' </dev/null 
 
 

2.) code from RudiC will give me always 1 as result maybe because my AIX is to old

 awk 'BEGIN {print srand()}'

 

3.) code from Corona668 work again perfect

 perl -e 'print time(), "\n";'
 

4.) Bakunin yes the %T Option available for the date Format on my very old AIX , but i need the time in seconds, therfore the solution i got from vgersh99 and Corona688 are fine

Thanks a lot for your help and Support

With Kind regards

A bit cleaner

perl -le 'print time'
1 Like

Hi Aia,

will try your code

Thanks a lot

I don't know how recent the ksh93 is on AIX, but you could also try:

printf '%(%s)T\n' now

when running ksh93 . It at least works on ksh version 93u+ 2012-08-01 .

Actually this is a solution:

date +'%T' | IFS=':' read hr min sec
time=$(( hr * 3600 + min * 60 + sec ))

This removes the necessity to use an external program (nawk, perl) and makes only use of standard (ksh-)features. Anyways, i am glad you have a solution that works.

I hope this helps.

bakunin

Hi bakunin,
The date +%T output gives you hours, minutes, and seconds (on a 24 hour clock) since midnight in the current timezone. The desired date +%s (which is not available on many UNIX systems, including AIX) gives you seconds since the Epoch (midnight at the start of January 1, 1970 UCT). You need a lot more information than what is provided by the current 24 hour clock time to convert that output to seconds since the Epoch.

I am well aware of the difference between epoch time and seconds since midnight. I was (see post #1) - and perhaps erroneously so - convinced that thread-o/p was looking for the seconds since midnight ("time in seconds"), not the epoch (from which the seconds since midnight can be derived too, with some effort). So i offered this as a perceived shortcut.

date +'%s' is, btw., available on (a recent) AIX, but probably not on AIX 4.3.2 (which, IIRC, should be around 1997 or 1998).

bakunin