SUMMARY - Convert lastchg field in shadow file to date

Alan Bradley - CPX WC AlanB at ComparexAfrica.co.za
Fri Nov 15 05:06:23 EST 2002


Hi All,

Thanks very much to:

John Leadeham
Bertrand Hutin
Jonas Bleberg

The answers consisted of me being sent 2 perl scripts (The one from Jonas
Bleberg, which I ended up using, is below) and also a suggestion to use Gnu
date, which is part of the shutils package available from
www.sunfreeware.com  -  Gnu date does date arithmetic:

$ date -s "1 January 1970 + 12000 days"
Sat Nov  9 00:00:00  2002

Perl script:
------------

#!/usr/local/bin/perl

# Output date format is YYYY-MM-DD

open( S, "/etc/shadow" );
while( <S> )
  {
  ($user,$lastchg) = (split /:/)[0,2];
  @t = localtime( $lastchg*86400 );
  printf "User %-8s last changed password %0.4d-%0.2d-%0.2d (%5d)\n",
         $user, $t[5]+1900, $t[4]+1, $t[3], $lastchg;
  }
close( S );

exit 0;


Regards,
Alan.


NOTICE: The contents of this message and any attachments are personal to the
sender and, whilst having been sent using the Comparex Africa (Pty) Ltd
e-mail system, are not, and should not be construed as having been sent on
behalf of Comparex Africa (Pty) Ltd.
_______________________________________________
sunmanagers mailing list
sunmanagers at sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers




More information about the summaries mailing list