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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting epoch seconds to readable date format 2

Status
Not open for further replies.

vivek1712

Technical User
Dec 17, 2002
47
IN
Hi ,


Can anybody help me with a shell or perl script that converts epoch seconds into dd/mm/yy format. My purpose is to write a script that will generate a mail to the user for changing his password as per the maxage setting. For this I need to read the lastupdate field in /etc/security/passwd. For checking the lastupdate field I'm using pwdadm -q $usernm , my OS is AIX 4.3.

Thanx in advance .

Best Regards,
vivek

 
If possible, could you post what the "epoch seconds" look like? My suspicion is either AIX has some utilities to convert it (but I do not know) or you need to develop some utilities yourself, which is not that hard. But post the seconds data and let us see what is doable
 
Assuming epoch seconds is what you get from perl using print time();

Create a script which accepts epoch seconds as the only argument and returns date and time, eg:

#!/usr/bin/perl
($sec,$min,$hour,$mday,$mon, $year,$wday,$yday,$isdst) = localtime(shift);
$mon++;
$year += 1900;
printf "%02d-%02d-%04d %02d:%02d:%02d\n",$mday,$mon,$year,$hour,$min,$sec;

Tested...
$ convert.pl 1051545709
28-04-2003 17:01:49
 
Thanx Ygor for ur script. Cruel I think u have seen the epoch seconds example from ygor's script.

I've done the conversion in the undermentioned way :
Eg : perl -e 'print scalar localtime(1066253412) , "\n";'

Best Regards,
vivek
 
Ygor,
Please add your solutions to the faq. Both (perl and non-perl) are clean and clear.

-Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top