Hi all,
I'm trying to write a script that will pass a "random" password to the htdbm command to reset an apache user password.
The goal here is to write the script in such a way that the person who is running the script doesn't know the password of the apache user they are resetting.
My problem right now is that I can't seem to get my variable that holds the new password into the htdbm command. this is line 24. I can't help but wonder if I'm doing something dumb here =/
Can someone look and see a way to accomplish my goal?
Code:
PS3='Option or Enter: '
PS4=''
DBDEST=/usr/local/apache/passwd/passwords.htdbm
LOGDEST=/var/log/audit/audit.log
# shell function to generate passwords
genpasswd() {
local l=$1
[ "$l" == "" ] && l=7
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
NEWPASS=`genpasswd`
echo $NEWPASS
# add a user
functionAdd()
{
echo "Enter the username as <FirstNameLastName>:"
echo
read NAME
htdbm $DBDEST $NAME < $NEWPASS
echo
echo "Added $NAME" >> $LOGDEST
}
# teh menu
select i in List Add Reset Remove Quit
do
case $i in
List) htdbm -l $DBDEST;echo;;
Add) functionAdd;;
# Comment) echo "COMMENT: Enter username to comment:";echo;read NAME;echo "Enter Comment:";echo;read COMMENT;htdbm -t $DBDEST $NAME $COMMENT;;
Reset) echo "RESET: Enter username to Reset:";echo;read NAME;htdbm $DBDEST $NAME;echo;echo "Reset $NAME" >> $LOGDEST;;
Remove) echo "REMOVE: Enter the username to remove:";echo;read NAME;htdbm -x $DBDEST $NAME;echo;echo "Removed $NAME" >> $LOGDEST;;
Quit) break;;
esac
done