diff --git a/scripts/bash/notifypwexp.sh b/scripts/bash/notifypwexp.sh index 7f7d11b..3fc2e0b 100755 --- a/scripts/bash/notifypwexp.sh +++ b/scripts/bash/notifypwexp.sh @@ -14,6 +14,8 @@ weekmode=7 #for daily cron: #weekmode=0 +debug=false + admins="system" declare -r aged=21 # minimum days after expiration before admins are emailed, set to 0 for "always" @@ -58,7 +60,9 @@ secondsperday=86400 # set this to 1 for no division #secondsperday=1 today=$(($($dateprog $useUTC $epochseconds $dateformat)/$secondsperday)) -echo "today: $today" +if [ "$debug" = true ]; then + echo "today: $today" +fi oIFS=$IFS # ### END SETUP ### @@ -93,44 +97,60 @@ users=$($awkprog -F: -v uidfield=$uidfield \ for user in $users; do - echo "user: $user" + if [ "$debug" = true ]; then + echo "user: $user" + fi IFS=":" usershadow=$($grepprog ^$user $shadowfile) - echo "usershadow 1: $usershadow" + if [ "$debug" = true ]; then + echo "usershadow 1: $usershadow" + fi # make an array out of it usershadow=($usershadow) - echo "usershadow 2: $usershadow" + if [ "$debug" = true ]; then + echo "usershadow 2: $usershadow" + fi IFS=$oIFS mustchange=${usershadow[$must]} - echo "mustchange: $mustchange" + if [ "$debug" = true ]; then + echo "mustchange: $mustchange" + fi disabledate=${usershadow[$disable]:-$doesntmust} - echo "disabledate: $disabledate" + if [ "$debug" = true ]; then + echo "disabledate: $disabledate" + fi # skip users that aren't expiring or that are disabled if [[ $mustchange -ge $doesntmust || $disabledate -le $today ]] ; then continue; fi; lastchange=${usershadow[$last]} - echo "lastchange: $lastchange" + if [ "$debug" = true ]; then + echo "lastchange: $lastchange" + fi warndays=${usershadow[$warn]:-$warndefault} - echo "warndays: $warndays" + if [ "$debug" = true ]; then + echo "warndays: $warndays" + fi expdate=$(("$lastchange" + "$mustchange")) - echo "expdate: $expdate" + if [ "$debug" = true ]; then + echo "expdate: $expdate" + fi threshhold=$(($today + $warndays + $weekmode)) - echo "threshhold: $treshhold" + if [ "$debug" = true ]; then + echo "threshhold: $treshhold" + fi if [[ $expdate -lt $threshhold ]]; - - gentemplate_userbody "$(($expdate - $today))" - then + gentemplate_userbody "$(($expdate - $today))" if [[ $expdate -ge $today ]]; then subject=$(eval "echo \"$usersubjecttemplate\"") @@ -145,6 +165,5 @@ do fi fi fi - - done +unset debug