Script Before AIX Lock User Account

How to know before AIX will lock your user account?

I cobbled this script together, and put it in the /etc/profile (ALL my users are forced to KSH).

#!/usr/bin/perl 

######### 
##### 
## 
# pwexpire - M. Cecil

# usage: pwexpire <username> 

# display next password expiration on current machine for specified 
# user. Do not allow non-root user to display another's expiry. 

## 
##### 
######### 

# Save off called program name for reporting errors 
$prog=$0; 
$prog=~s/.*\///; 

# What is the subject user? 
$user=$ARGV[0]; 

# What time is it now? (Not used yet... Would be for countdown-style display) 
$now=time(); 

# Check proper invocation 
if ( $#ARGV != 0 ) { 
print STDERR "usage: $prog <user>\n"; 
exit(1); 

# What process called this one? 
$ppid=getppid(); 

# What user owned that process? 
$puser=`ps -F user -p $ppid | tail -1`; 
chomp($puser); 
$puser=~s/ *//; 

# If that user isn't root, and if the calling user does not match the subject 
# of the script, then bail 
if ( $puser ne "root" && $puser ne $user ) { 
print STDERR "$prog: only root is allowed to check another user's expiry.\n"; 
exit (1); 

# Obtain maximum PW age of the subject user 
$maxage_in_weeks=`lsuser -a maxage $user 2>/dev/null`; 
chomp($maxage_in_weeks); 
$maxage_in_weeks=~s/.*=//; 

# if that return was nothing, then the user does not exist. 
if ( "$maxage_in_weeks" eq "" ) { 
print STDERR "$prog: $user does not exist.\n"; 
exit (1); 

# Display non-expiring status 
} elsif ( $maxage_in_weeks == 0 ) { 
print "$user - password does not expire.\n"; 

# Else, compute the next expiration 
} else { 
# Discover the last time the user updated its password. 
$lastupdate=`lssec -f /etc/security/passwd -a lastupdate -s $user`; 
chomp($lastupdate); 
$lastupdate=~s/.*=//; 

# Multiply max age in weeks times seconds per week, and add to 
# last update time. 
$maxage_in_seconds=$maxage_in_weeks*604800; 
$expire_date=$lastupdate+$maxage_in_seconds; 
my $expire=localtime($expire_date); 

# And, show the result. 
print "$user - expires on ${expire}.\n"; 

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.