I wanted a script to visually warn users on my system that their password is about to expire. I found this one here.
The thing is, the author of that script gets the number of days to password expiration by converting dates to seconds, subtracting and then passing seconds to days.
The problem is that my system is outputting those dates as "ago 08, 2018" (for today). If I stick to using date command for date conversion to seconds as the author did, then I get an error: invalid date 'ago 08, 2018'.
Any help?
Here is the full script:
#! /bin/bash
# Issue a desktop notification if the user password is about to expire
# Uses the "chage" command frome the "passwd" package (likely installed)
# Best added to the session startup scripts
# get password data in array
saveIFS=$IFS
IFS=$'\n'
chagedata=( $(chage -l $USER | cut -d ':' -f 2 | cut -d " " -f 2-) )
IFS=$saveIFS
# obtain times in seconds
now=$(date +%s)
expires=$(date +%s -d "${chagedata[1]}")
# compute days left (roughly...)
daysleft=$(( ($expires-$now)/(3600*24) ))
echo "Days left: $daysleft"
# leave some evidence that the script really ran at startup
echo "Days left: $daysleft" > /var/tmp/$(basename $0).out
# determine and send the notification (stays mute if outside the warning period)
if [[ $daysleft -le 0 ]]
then
notify-send -i face-worried.png -t 0 "Password expiration" "Your password expires within a day"'!'
elif [[ $daysleft -le ${chagedata[6]} ]]
then
notify-send -i face-smirk.png -t 0 "Password expiration" "Your password expires in $daysleft days."
fi
LANG=en_US.UTF-8 chage -l $USER . . .
date
's documentation states, useLC_TIME=C
.