To expire the password set the expiration date to a date in the past:
chage -E 0 username # 0 is January 1, 1970; 14496 is 9/9/9
To remove the expiration use -1:
chage -E -1 username
Combine these with Kyle's script.
However, you can get your user
and date_change
using only one call to awk
:
# Bash
read user date_change <<< $(echo $line | awk -F: '{print $1, $3}')
or
# Bash
read user date_change < <(echo $line | awk -F: '{print $1, $3}')
or
# Bourne
read user date_change <<EOF
`echo $line | awk -F: '{print $1, $3}'`
EOF
However, awk
is unnecessary:
while IFS=: read -a line
do
date_change=${line[2]}
user=${line[0]}
# Have they changed their password since I told them to on Jul 1?
if [[ $date_change <= 14426 ]]; then
# Expire their password, that'll get their attention
chage -E 0 $user
fi
done < /etc/shadow