The Problem
I am attempting to update passwords for a large list of users using htpasswd
. I am using a csv file to pull in the new passwords.
When the script runs it appears to successfully update the users. However, users are unable to log in using their new passwords.
here is the script:
#!/bin/bash
# Bash to update passwords from csv
CSV=intranet_users.csv
OLDIFS=$IFS
IFS=','
[ ! -f $CSV ] && { echo "$CSV file not found"; exit 99; }
while read name dept username password
do
if [ "${username}" != '#N/A' ] && [ "${username}" != 0 ]; then
echo "Resetting password for $username to: ${password}"
htpasswd -b /path/to/passwdFile $username '${password}'
fi
done < $CSV
IFS=$OLDIFS
If I run the script against a test csv with no special characters in the passwords, it works.
If I run htpasswd -b /path/to/passwdFile username 'password'
on the command line (passwords with special chars), everything works as it should.
Why does the script fail to set the password correctly?
What I have tried
I have tried running htpasswd using eval
I have tried various methods of quoting $password i.e "'", '\'', "\'"