I am preparing script , if user's password needs to be expire in one week. script is running, but gives output in 0.
please help, if any one worked on it..
User details.
[root@localhost ~]# chage -l natasha
Last password change : Feb 09, 2020
Password expires : Apr 01, 2020
Password inactive : never
Account expires : never
Minimum number of days between password change : 40
Maximum number of days between password change : 52
Number of days of warning before password expires : 7
script -------
#!/bin/sh
SUBJECT="Information About User Password Expiration on "`date`""
MESSAGE="/tmp/user-expiry.txt"
MESSAGE1="/tmp/user-expiry-1.txt"
TO="abc@gmail.com"
echo "-------------------------------------------------" >> $MESSAGE1
echo "UserName The number of days the password expires" >> $MESSAGE1
echo "-------------------------------------------------" >> $MESSAGE1
for usern in natasha
do
today=$(date +%s)
userexpdate=$(chage -l $usern | grep 'Password expires' |cut -d: -f2)
passexp=$(date -d "$userexpdate" "+%s")
exp=`expr \( $passexp - $today \)`
expday=`expr \( $exp / 86400 \)`
echo "$usern $expday" >> $MESSAGE
done
cat $MESSAGE | awk '$2 <= 10' >> $MESSAGE1
mail -s "$SUBJECT" "$TO" < $MESSAGE1
Output.........
root@localhost ~]# cat /tmp/user-expiry-1.txt
natasha 0
natasha 0
natasha 0
-------------------------------------------------
UserName The number of days the password expires
-------------------------------------------------
natasha 0
natasha 0
natasha 0
natasha 0