分类:
2008-05-11 22:07:35
cat <<'!' >/bin/expire.ksh
#!/usr/bin/ksh
#SECTION1 -- Please change these following UPPERCASE variables, if you need.
CC=" "
USERLIST="user1 user2 user3"
maxage=`grep -p default: /etc/security/user | awk '$1 ~ /maxage/ {print $3}'`
expiretime=`expr $maxage \* 604800` # 1 week = 604800 seconds
threshold=`expr $expiretime - 604800`
currenttime=`perl -le "print scalar time" 2>/dev/null`
#SECTION2 -- Check whether the user in USERLIST will expire.
> /tmp/expire.txt
for i in $USERLIST; do
grep -p ^${i}: /etc/security/passwd | awk '$1 ~ /lastupdate/ {print $3}' | read lastupdate &&
if [ $threshold -lt `expr $currenttime - $lastupdate` ]; then
echo " Expire time of user $i is "`perl -le "print scalar localtime($lastupdate + $expiretime)" 2>/dev/null`"." >> /tmp/expire.txt
fi
done
#SECTION3 -- If find some user will expire, send out a mail.
if [ -s /tmp/expire.txt ]; then
mail -s "User expire warning mail from `hostname` at `date +'%y-%m-%d %H:%M'`" -c "$CC" $SENDTO fi
!
NOTICES:
1)The crontab could be set like this: 0 9 * * * /usr/bin/expire.ksh .
2)The owner of the file should be set to xxx. Because our team maybe need modify the UPPERCASE variables sometime.