Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting epoch date to date. 4

Status
Not open for further replies.

keltob

MIS
Apr 24, 2002
2
US
IBM in all its wisdom decided that on all date related returns on user inquiries would be seconds counting back to the epoch (00:00:00 Jan 1, 1970). So if I wanted to get the last time I logged into AIX I would get somthing like this; 1019680832. Is there a way to covert this to a date string that resembles this; Apr 24 2002 10:00am?
 
keltab,

Simple :

cnvdate 1019680832

Best of luck PSD
IBM Certified Specialist - AIX V4.3 Systems Support
IBM Certified Specialist - AIX V4 HACMP
 
If you want to see when a user last logged in, try

last|grep username

or maybe

last|pg

These will give more than just last login time.
 
Epoch started January 1st 1970 and is count of seconds since then
 
The only way that I know of doing this is to write a C program to do the conversion. The one that I use is listed below:


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

void main(int argc, char *argv[])
{

if (argc != 2) {
fprintf(stderr, &quot;Usage: %s int\n&quot;, *argv);
exit(1);
}

printf(&quot;%s&quot;,ctime( (time_t *)argv[1] ));

}



Regards,
Chuck
 
And on another note - it was not IBM that created the epoch at Jan, 1970 - it was Bell Labs, the original writers of UNIX. They chose the date of the epoch. All UNIXes have the same start as the epoch because in reality they all have the same common ancestor.

Bill.
 
Cool, Bill. More info, if anyone is interested, from The New Hacker's Dictionary:

Unix /yoo'niks/ n.

[In the authors' words, &quot;A weak pun on Multics&quot;; very early on it was `UNICS'] (also `UNIX') An interactive time-sharing system invented in 1969 by Ken Thompson after Bell Labs left the Multics project, originally so he could play games on his scavenged PDP-7. Dennis Ritchie, the inventor of C, is considered a co-author of the system. The turning point in Unix's history came when it was reimplemented almost entirely in C during 1972-1974, making it the first source-portable OS. Unix subsequently underwent mutations and expansions at the hands of many different people, resulting in a uniquely flexible and developer-friendly environment. By 1991, Unix had become the most widely used multiuser general-purpose operating system in the world - and since 1996 the variant called Linux has been at the cutting edge of the open source movement. Many people consider the success of Unix the most important victory yet of hackerdom over industry opposition (but see Unix weenie and Unix conspiracy for an opposing point of view). See Version 7, BSD, Linux.
 
Here is an extension of this discussion. I have been working on this for 2 weeks, and finally came up with something functional.

This script reports the last time each user logged on, in people readable format. Enjoy:


Code:
#! /bin/ksh

lsuser -c -a time_last_login ALL | egrep -v &quot;^#&quot; > user_last_login.txt

echo &quot;\n Last Login Datetime       User&quot;
awk -F&quot;:&quot; '{ if($2 != &quot;&quot;) {print $0} }' user_last_login.txt | while read line;do

  loginuser=`echo $line | cut -d&quot;:&quot; -f1`
  logintime=`echo $line | cut -d&quot;:&quot; -f2`
  perl -we &quot;print scalar localtime $logintime&quot;
  echo &quot; $loginuser&quot;

done


If I knew perl better, this script would be cleaner (I think). Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top