Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting lastupdate from seconds since epoch to a date

849 views
Skip to first unread message

James Dennis

unread,
Dec 5, 2001, 5:53:07 PM12/5/01
to
I have an entry in the /etc/ssecurity/passwd file with lastupdate =
1007576841.

Is there a built in function in AIX to convert that to a normal date,
such as Nov. 14, 2001?

Thanks!

Jamie

Jens-Uwe Mager

unread,
Dec 5, 2001, 6:26:31 PM12/5/01
to

$ perl -le 'print scalar localtime(shift);' 1007576841
Wed Dec 5 19:27:21 2001

--
Jens-Uwe Mager <pgp-mailto:62CFDB25>

Ralph Corderoy

unread,
Dec 8, 2001, 2:12:22 PM12/8/01
to
Hi Jens-Uwe,

> > I have an entry in the /etc/ssecurity/passwd file with lastupdate =
> > 1007576841.
> >
> > Is there a built in function in AIX to convert that to a normal
> > date, such as Nov. 14, 2001?
>
> $ perl -le 'print scalar localtime(shift);' 1007576841
> Wed Dec 5 19:27:21 2001

Is the time in that file local? I'd have expected it to be GMT
requiring

perl -le 'print scalar gmtime 1007576841'

Cheers,


Ralph.

Jens-Uwe Mager

unread,
Dec 8, 2001, 6:40:22 PM12/8/01
to

All time values in this form (time_t) are in GMT, this is the reason I
used localtime. It is in most instances interesting when a particular
session happened in local wall clock time. Unless you are with the
military and have to write down a report in zulu time gmtime is probably
not very interesting.

V K Agarwal

unread,
Dec 8, 2001, 10:39:16 PM12/8/01
to
j...@anubis.han.de (Jens-Uwe Mager) wrote in message news:<slrna1598...@anubis.han.de>...

Can someone please write this command [#$ perl -le 'print scalar
localtime(shift);' 1007576841 ] in ksh. It really helps a lot on my
AIX 4.3.3 systems.

I do not have perl on my AIX 4.3.2 system, I have perl on my AIX 4.3.3
system.
Other alternate may to get perl package for AIX 4.3.2 (I do not know
how can I get perl for AIX 4.3.2). Is it possible to get perl from AIX
4.3.3 CDs and use it on AIX 4.3.2 systems ?

Enjoy,
VK

Ralph Corderoy

unread,
Dec 10, 2001, 6:30:13 PM12/10/01
to
Hi Jens-Uwe,

> > Is the time in that file local? I'd have expected it to be GMT
> > requiring
> >
> > perl -le 'print scalar gmtime 1007576841'
>
> All time values in this form (time_t) are in GMT, this is the reason
> I used localtime.

You're of course, absolutely right. Don't know what I was thinking.

Sorry.


Ralph.

Dell Coleman

unread,
Dec 10, 2001, 7:07:55 PM12/10/01
to
On Sun, 9 Dec 2001 03:39:16, vkag...@conoco.com (V K Agarwal) wrote:

> Can someone please write this command [#$ perl -le 'print scalar
> localtime(shift);' 1007576841 ] in ksh. It really helps a lot on my
> AIX 4.3.3 systems.
>
> I do not have perl on my AIX 4.3.2 system, I have perl on my AIX 4.3.3
> system.
> Other alternate may to get perl package for AIX 4.3.2 (I do not know
> how can I get perl for AIX 4.3.2). Is it possible to get perl from AIX
> 4.3.3 CDs and use it on AIX 4.3.2 systems ?
>

You can get a copy of perl from Bull at http://freeware.bull.net
Click on 4.3 and 5.1 under downloads.

--
Dell Coleman
de...@aleph.tum.com

Ralph Corderoy

unread,
Dec 11, 2001, 6:14:03 AM12/11/01
to
Hi VK,

> > > > $ perl -le 'print scalar localtime(shift);' 1007576841
> > > > Wed Dec 5 19:27:21 2001
>

> Can someone please write this command [#$ perl -le 'print scalar
> localtime(shift);' 1007576841 ] in ksh. It really helps a lot on my
> AIX 4.3.3 systems.

I don't think it's easily possible in ksh. Here's a C implementation.
Save it as localtime.c and then do `cc -O -o localtime localtime.c' to
create a `localtime' command. Supply one or more numbers on the
command line.

---- snip ----

#include <string.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char *argv[])
{
char *progname;
time_t tim;
char *end;

(progname = strrchr(*argv, '/')) ? progname++ : (progname = *argv);
while (*++argv) {
tim = strtol(*argv, &end, 10);
if (*end) {
fprintf(stderr, "%s: non-digit argument: %s\n",
progname, *argv);
return 1;
}
fputs(asctime(localtime(&tim)), stdout);
}

return 0;
}

---- snip ----

Here's it being used on AIX.

$ ./localtime 0 1007576841
Thu Jan 1 00:00:00 1970
Wed Dec 5 18:27:21 2001

Interesting, on Linux I get a different answer for 0 but not for
1007576841.

% ./localtime 0 1007576841
Thu Jan 1 01:00:00 1970
Wed Dec 5 18:27:21 2001

Both machines have a timezone of GMT.

Cheers,


Ralph.

Charles Seeger

unread,
Dec 11, 2001, 4:09:39 PM12/11/01
to
In article <9v4ppr$6in$1...@inputplus.demon.co.uk>,

Ralph Corderoy <ra...@inputplus.demon.co.uk> wrote:
| Hi VK,
|
| > > > > $ perl -le 'print scalar localtime(shift);' 1007576841
| > > > > Wed Dec 5 19:27:21 2001
| >
| > Can someone please write this command [#$ perl -le 'print scalar
| > localtime(shift);' 1007576841 ] in ksh. It really helps a lot on my
| > AIX 4.3.3 systems.
|
| I don't think it's easily possible in ksh. Here's a C implementation.
| ...

Hey, that almost sounds like a challenge. 8-)

I'm too lazy to go to an AIX box at the moment, but this works
on Solaris:

set -- $( print "0t$time>Y\n<Y=Y" | adb )

though the output may look like either "1999 Mar 15 22:38:30"
or "Fri Sep 13 00:00:00 1986", depending on the adb version.
The last that I checked, neither gdb nor dbx were useful for this.
It might be possible to script a debugger to run date and inject
an arbitrary time value, but I've never got around to trying that,
much less a pure ksh implementation. Generating the epoch time
from date output with ksh isn't too unreasonable:

set -- $(date -u '+%Y %j %H %M %S')
DAYS=$(( 365*($1 - 1970) + ($1 - 1969)/4 + $2 - 1 ))
UNIXTIME=$(( $5 + 60*($4 + 60*($3 + 24*$DAYS)) ))

so the inverse should be tractable and, in fact, I've implemented
a gmtime ksh function. It's a little long and ugly, so I won't
include it here. The only remaining parts would be to deal with
the timezone offset and formatting the output. Yeah, I have a
ksh strftime function already. Oh, wait, I have a tzoffset, too.
Let's see...

$ . ./libtime.ksh
$ unixtime
1008102925
$ gmtime 1008102925
25 35 20 11 11 101 2 344 0
$ strftime "%C" 25 35 20 11 11 101 2 344 0
Tue Dec 11 20:35:25 EST 2001
$ tzoffset
-18000
$ gmtime $(( 1008102925 + $(tzoffset) ))
25 35 15 11 11 101 2 344 0
$ strftime "%C" 25 35 15 11 11 101 2 344 0
Tue Dec 11 15:35:25 EST 2001
$ strftime "%C" $( gmtime $(( 1008102925 + $(tzoffset) )) )
Tue Dec 11 15:35:25 EST 2001

... voila! So all the parts are there after all.

http://www.cise.ufl.edu/~seeger/dist/libtime.ksh

It's pre-production code that hasn't been ported around,
but it should give anyone wanting to do this a start.
User beware, etc., etc.... I'll try to get an updated
version of localtime in there later this week. Then we
may have to work on portability to AIX and fix up a few
rough edges.

Cheers,
Chuck
--
Charles Seeger <see...@cise.ufl.edu>

Ralph Corderoy

unread,
Dec 12, 2001, 8:24:19 AM12/12/01
to
Hi Chuck,

> > I don't think it's easily possible in ksh. Here's a C
> > implementation. ...
>
> Hey, that almost sounds like a challenge. 8-)

If it was it seems I was too late, you already having completed the
task in March 1999 :-) I don't think it would be considered easy
though.

Seriously, great script, but I still think the easiest way is to either
write small programs in C, or install GNU date.

% date -d '1 Jan 1970 + 7200 seconds'
Thu Jan 1 02:00:00 BST 1970

> I'm too lazy to go to an AIX box at the moment, but this works
> on Solaris:
>
> set -- $( print "0t$time>Y\n<Y=Y" | adb )

It works on my AIX 3.2.5 system. Could you enlighten me as to the
meaning of

0t3600>Y
<Y=Y

Cheers,


Ralph.

0 new messages