Powered By Blogger

Thursday, October 16, 2014

Checking password expiration on Solaris using Script

# Copy /etc/shadown to temp directory (I am copying to /home/ramkumar and delete   #after) 
#!/usr/bin/bash
if [ $# -eq 0 ]
   then
    echo "You need to pass user as argument"
    exit 1
fi
COUNT=`grep $1 /home/ramkumar/shadow|wc -l`
if [ $COUNT != 1 ]
  then
  echo "User is not valid"
  exit 1;
fi

CURRENT_CH=`grep $1 /home/ramkumar/shadow | cut -d: -f3`
HOST=`uname -n`

LAST_CHA=`/bin/perl -e 'print int(time/(60*60*24))'`
# Compute the age of the user's password

AGE=`echo $LAST_CHA - $CURRENT_CH | /usr/bin/bc`
echo "last Changed" $AGE " days ago"

# Password expiration

EXPIRE=`echo 90 - $AGE | /usr/bin/bc`
if [ $EXPIRE -lt 0 ]
  then
   EXP=`echo $EXPIRE|sed 's/-//g'`
    echo "$1 password on $HOST expired  $EXP days ago"
  else
    echo "$1 password on $HOST expires in $EXPIRE days"
fi

No comments:

Post a Comment

Welcome to the UNIX world