I've searched everywhere I can think of, and am not able to get this to work. I need to add the user "www-data" to the sudoers file to run two commands with no password, namely "/usr/sbin/useradd" and "usr/sbin/chpasswd". I need this for a script that will automatically create a user and set their password. the line I'm using in the sudoers file is below. I've tested removing the useradd references, and the script fails. However, I can't get the chpasswd command to work without the password.
www-data hostname=NOPASSWD: /usr/sbin/useradd, /usr/sbin/chpasswd
sudo useradd -m $1
echo 1 - user added
sudo echo "$1:$2" | chpasswd
echo 2 - pass changed