Tuesday, 10 November 2015

Password Expiry Monitoring and Notification Script.


00 10 * * *  /bin/sh -xv /home/psoft/scripts/pwd_exp_monitor.ksh > /tmp/pwd_exp_monitor.logs &


#!/bin/bash
################################################################################
#Script: Monitor for password expire of the critical accounts psoft or oracle.
#Script Author : zafrulla.khan@xyz.com
#Date : 11/Nov/2015
#Version 2.0
################################################################################

export user_check=$(/usr/bin/whoami);
HOST_NAME=$(hostname | awk -F_ '{ print $1}')
MAILLIST="zafrulla.khan@xyz.com"
echo $user_check;
for (( i=1;i<=10;i++ ))
do
if [ "$(/usr/bin/chage -l $user_check|grep expires|grep Password|awk -F':' '{print $NF}'|sed  's/^ *//')" == "$(date --date="$i day" +"%b %d, %Y")" ]; then
echo "$user_check Password will expire in $i days, Please do change the password as early as possible"

/bin/mailx -s "$HOST_NAME - IMPORTANT $user_check password will expire in $i days - $(/bin/date +%F)" -r noreply@prologis.com $MAILLIST <<-EOF
Hello DBA/ADMIN Team,

$i Days to go.

Please consider changing the password of the user "$user_check" in host "$HOST_NAME" as early as you can.

If not changed before it expires, there will be impact on the monitoring and as well on the cron jobs execution.

==============================================================================
Password Expire Monitoring and Notification Script
==============================================================================
This script is located in the directory $(cd $(dirname $0);echo $PWD)
Host Name : $HOST_NAME
Script Name : "${0##*/}"
Version  : 2.0
===============================================================================

EOF
fi
done





No comments:

Post a Comment