Summary: Password expiry notification script

From: Raj <rajwin_at_yahoo.com>
Date: Fri Aug 12 2005 - 02:17:38 EDT
Dear All,
   The scrpits which i used for implementing the password notification are attached herewith. Thanks to kalyan for that.
 
Regards,
Raj
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
#!/bin/ksh
#Author:Kalyan Manchikanti
#C:Date:02/08/2005
#Check the Shadow table for the epoch value and warn the users / admins of password expiry seven days in advance
#This script needs the epoch.pl script to exist

ID=`/usr/bin/id | /usr/bin/cut -d" " -f1`
if [[ "${ID}" != "uid=0(root)" ]]
then
   echo "You should run as root"
   exit 1
fi

SHADOW=/etc/shadow
#Location of the epoch.pl script. Change it to wherever you are going to keep the epoch.pl script..
ESCPT=/home/kmanchi/bin/epoch.pl
HOSTNAME=`hostname`
#Email addresses of the admins / users needing the  notification
ADMINS="xyz@zy.com,abc@abcd.com"

for i in `cat $SHADOW`
do
LGN=`echo $i |awk -F: '{print \$1}'`
MAXDAYS=`echo $i | awk -F: '{print \$5}'`
echo "$MAXDAYS"
EPOCH=`echo $i |awk -F: '{print \$3}'`
EVAL=`$ESCPT $EPOCH | awk '{print \$2}'`
#echo "$EVAL"
		 if [[ $EVAL == `expr $MAXDAYS - 7` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in a week. Please change it ASAP" | mailx -s 'password expiry' $ADMINS
		 elif [[ $EVAL == `expr $MAXDAYS - 6` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in 6 days. Please change it ASAP" |  mailx -s 'password expiry' $ADMINS		 
		 elif [[ $EVAL == `expr $MAXDAYS - 5` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in 5 days. Please change it ASAP" |  mailx -s 'password expiry' $ADMINS		 		 
		 elif [[ $EVAL == `expr $MAXDAYS - 4` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in 4 days. Please change it ASAP" |  mailx -s 'password expiry' $ADMINS		 		 
		 elif [[ $EVAL == `expr $MAXDAYS - 3` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in 3 days. Please change it ASAP" |  mailx -s 'password expiry' $ADMINS		 		 
		 elif [[ $EVAL == `expr $MAXDAYS - 2` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in 2 days. Please change it ASAP" |  mailx -s 'password expiry' $ADMINS		 		 
		 elif [[ $EVAL == `expr $MAXDAYS - 1` ]]
		 then
		 echo "Password for unix user $LGN on `hostname` is going to expire in 1 day. Please change it ASAP" |  mailx -s 'password expiry' $ADMINS		 		 
		 elif [[ $EVAL == "$MAXDAYS" ]]
		 then
		 echo "PASSWORD FOR USER $LGN HAS EXPIRED.PLEASE CHANGE IT ASAP TO AVOID JOBS FAILING"
		 fi
done
#!/bin/perl -w
#Argument to this script is the epoch (third field in /etc/shadow) value

use integer;


if ($#ARGV != 0) {
    print "Usage: epoch.pl <number>\n";
    exit 1;
}

$input_day=$ARGV[0];
if ($input_day =~ /(\D+)/) {
    print "ERROR: Please enter a number!!!\n";
    exit 1;
}

$clktime=time;

$curr_day=$clktime/86400;

$diff=$curr_day - $input_day;

if ($diff < 0) {
    $diff=-1*$diff;
    print "$input_day: $diff days from current day\n";
}
else {
    print "$input_day: $diff days to current day\n";
}
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Fri Aug 12 02:18:08 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:50 EST