Given the script below, can someone help me get past this error ? The script calculates days since the unix epoch and given the password expiration date, comes back telling me how many days till they are gonna get locked out. Its the let/math that is getting me. Ive tried quotes, different spacing around the minus operator all to no avail.
#!/usr/bin/bash
#
# Filename: pwx
# Description: Script to tell when A password for a user expires
# Usage: pwx username
#
function daysSince1970 {
[[ -x /usr/bin/nawk ]] && AWK=/usr/bin/nawk || AWK=/usr/bin/awk
date +"%j %Y" | $AWK -v VERBOSE=$1 '
{
DAYOFYEAR=$1
CURRENTYEAR=$2
DAYS=-1 # Because it is not 1 day since 01/01/1970 until 02/01/1970.
if (VERBOSE) { printf("%8s%8s%8s\n","Year","Days","Total") }
for (YEAR=1970; YEAR < CURRENTYEAR; YEAR++) {
if (YEAR % 4 == 0) {
if (YEAR % 100 == 0) {
if (YEAR % 1000 == 0) {
YEARDAYS=366
} else {
YEARDAYS=365
}
} else {
YEARDAYS=366
}
} else {
YEARDAYS=365
}
DAYS+=YEARDAYS
if (VERBOSE) { printf("%8s%8d%8d\n",YEAR,YEARDAYS,DAYS) }
}
DAYS+=DAYOFYEAR
if (VERBOSE) { printf("%8s%8d",YEAR,DAYOFYEAR) }
printf("%8d\n",DAYS)
}'
}
case $1 in
"")
echo -e "Usage: $0 username"
;;
*)
SEVENTY=$(daysSince1970)
PWCD=$(grep $1 /etc/shadow| awk -F":" '{print $3}')
PWED=$(grep $1 /etc/shadow| awk -F":" '{print $5}')
let PWTIME=SEVENTY-PWCD
if [[ $PWTIME -gt $PWED ]]
then
echo -e "Password expired"
else
let LEFT=PWED - $PWTIME ####This is the line that is erroring out
echo -e "$1 password good $LEFT to expire\n"
fi
;;
esac