home

Quickies, by Andrea Olivato

text

Bash and Expect script to change user password

As passwd does not support —stdin in my linux system, I needed a different way to set an user password from a bash script. This seemed a good alternative to me.

Please note that expect might not be installed on your system. Be sure to install it before running the script. Note that using export HOSTIGNORE the passwd prompted won’t be stored in bash history file.

USEER="embrace";
NEWPWD="segreto";
export HISTIGNORE="expect*";

expect -c "
        spawn passwd $USEER
        expect pwd
        send \"$NEWPWD\r\"
        expect ad
        send  \"$NEWPWD\r\"
        expect eof"

export HISTIGNORE="";

2 years ago

June 10, 2009
Comments (View)
blog comments powered by Disqus