Password Expiration Notification

Hello,

I want to write a script to check for the password expiration date in each server for the user by logging to each server and notify user through mail. If password is about to expire or if already expired , it should also be notified to user by mail. Any help or idea to build this will be very much appreciative.

i think this script will help you...

#!/usr/bin/ksh
function juliandate {
day=$1
month=$2
year=$3
 ((standard_jd = day - 32075 + 1461 * (year + 4800 - (14 - month)/12)/4 + 367 * (month - 2 + (14 - month)/12*12)/12 - 3 * ((year + 4900 - (14 - month)/12)/100)/4))
 ((jd = standard_jd-2400001))
return $jd
}
######
#MAIN#
######
userid=$USER
 if [ "$userid" = "root" ]
 then
   awk -F ":" '{print $1}' /etc/shadow  > userlist.txt
   while read User
   do
     chage -l $User > userdetail.txt
     Password_Expiry_Date=`awk '/Password Expires/' userdetail.txt | awk -F ":" '{print $2}'`
     Warning_days=`awk '/Warning/' userdetail.txt | awk -F ":" '{print $2}'`
     P_Expiry_Date=$(date -d "$Password_Expiry_Date" +%Y-%m-%d)
     Expiry_Date=`echo $P_Expiry_Date | awk -F "-" '{print $3}'`
     Expiry_Month=`echo $P_Expiry_Date | awk -F "-" '{print $2}'`
     Expiry_Year=`echo $P_Expiry_Date | awk -F "-" '{print $1}'`
     Today=$(date -d "`date`" +%Y-%m-%d)
     Date=`echo $Today| awk -F "-" '{print $3}'`
     Month=`echo $Today | awk -F "-" '{print $2}'`
     Year=`echo $Today | awk -F "-" '{print $1}'`
     juliandate $Date $Month $Year
     julianday1=$?
     juliandate $Expiry_Date $Expiry_Month $Expiry_Year
     julianday2=$?
     diff_days=`expr $julianday2 - $julianday1`
     if [ $diff_days -le $Warning_days ]
     then
       if [ $diff_days -eq 0 ]
       then
         mailx -s "RENEW PASSWORD TODAY ITSELF" $User@mail.com  < message1.txt
       elif [ $diff_days -lt 0 ]
       then
          mailx -s "Your Password Expired" $User@mail.com < message2.txt
       else
          echo "Your password is going to expire in $diff_days day(s)" > message3.txt
          mailx -s "Renew Password" $User@mail.com < message3.txt
         fi
     fi
   done < userlist.txt
 else
   echo "You need root permission to run this script"
 fi

:slight_smile:

remove the "mail.com" and put your mail domain name there.....
you can set this script as a cron job in the server's and it will send mail's accordingly to the user's by verifying their password expiration date.
Edit the message according to your desire. if you placing the message in other directories, don't forget to mention the path..