Write your script add_user.sh like this (mind the quotes):
#!/bin/sh
adduser -u "$1" -p "$2" -g users -s /bin/bash
Render it executable:
me@somewhere$ chmod +x add_user.sh
And call it from within php as:
<?php
$command="/path/to/add_user.sh ".escapeshellarg($name)." ".escapeshellarg($pass);
exec ($command,$output=array(),$return_value);
if($return_value!==0) {
# Oh dear! something bad happened
}
?>
(I don't have php installed here, so I can't thoroughly test my answer)
If you don't want to use your auxilliary script, you can directly do:
<?php
$command="/path/to/adduser -u ".escapeshellarg($name)." -p ".escapeshellarg($pass)." -g users -s /bin/bash";
exec ($command,$output=array(),$return_value);
if($return_value!==0) {
# Oh dear! something bad happened
}
?>
Please make sure you test the return value (as I did). You'll have the command's output in the array $output.
Using escapeshellarg for each argument is much safer than calling escapeshellcmd on the already built in full command.
passthru("add_user.sh -u $NAME -p $PASS");.$NAMEis coming from a web form, then you had make ABSOLUTELY sure that you're using proper methods to pass that to a command line app. Consider what happens if the user enters; rm -rf /as their username... e.g. php.net/escape_shell_arg