#!/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 at zy.com,abc at 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";
}

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 24-May-2008 13:26 by jeem