#Author: Anil Narayanan
 #Purpose: Shell Script to extract the number of days since the password was last changed on ESX servers. Output saved in CSV file.
 #Version: 1

 echo "========================================================================================"
 echo "Author: Anil Narayanan"
 echo "Purpose: Shell Script to extract the number of days since the password was last changed on ESX servers."
 echo "Version: 1"
 echo "========================================================================================"
 echo ""

header="Serial,User,Pasword Last Changed"
 echo $header > /tmp/`hostname -s`_LPwdChg.csv
 id=$(cut -f1 -d : /etc/passwd)
 inc=0
 for uid in $id
 do
 inc=`expr $inc + 1`
 lchgdate="$(/usr/sbin/lchage -l $uid | grep -i "Last Change" | cut -f2 -d : )"
 sdate=$(date -d $lchgdate +%s)
 edate=$(date +%s)
 diffdate=`expr $edate - $sdate`
 days="`expr $diffdate / 86400` Days"
 line="$inc,$uid,$days"
 echo $line
 echo $line >> /tmp/`hostname -s`_LPwdChg.csv
 done

Advertisement