Originally posted by: SystemAdmin
I got this from the aix google group a little bit ago. part shell script and part perl script. Both are listed below:
#!/bin/ksh
#
-
expired_pw.sh
#
USER=$1
SERVER=`uname -n`
#
-
We need perl for telling us the time in seconds
#
if
-x /usr/local/bin/perl ; then
echo
echo "---- Password expiration information for user ${USER} on ${SERVER}."
echo
# get current time
seconds_since_epoch=`/usr/local/bin/perl -e 'print time;'`
# get maxage atribute
maxage=`/usr/sbin/lsuser -a maxage $USER | /usr/bin/awk -F '=' '{print $2 }'`
#-- remember, maxage in AIX is in weeks
(( Maxdays = maxage * 7 ))
if (( maxage > 0 )) ; then
(( maxage_seconds = maxage * 7 * 24 * 3600 ))
# Get the time the password was last updated
lastupdate=`sudo /usr/bin/pwdadm -q $USER | grep lastupdate | awk -F'=' '{pr
int $2}`
###
# convert the unix date value to readable date format using perl script.
###
updated_last=`last_pw_change_date.prl $lastupdate`
# Now see what happens
if (( seconds_since_epoch > lastupdate + maxage_seconds )) ; then
print "Password has expired. User is required to change it ASAP."
exit 1
else
((daystoexpire = (lastupdate + maxage_seconds - seconds_since_epoch) / (24
* 3600 )))
fi
fi
fi
echo "Password will need to be changed at least ${maxage} weeks \
(${Maxdays} days)."
echo "Password was last changed on ${updated_last}"
echo "Password will expire in ${daystoexpire} days."
uses this perl script:
#!/usr/local/bin/perl -w
#
-
last_pw_change_date.prl
#
-
takes argument in from /etc/security/password and performs
-
a "print scalar gmtime(arg1)"
#
$numargs = @ARGV;
if ($numargs != 1) {
print "\nUsage: $0 numeric_rep_of_date\n";
print "example: $0 1129889197\n\n";
exit;
}
$lastchanged = shift;
print scalar gmtime($lastchanged), "\n"
#AIX-Forum