Click to See Complete Forum and Search --> : useradd shell scripting problem!


tjeonnybravo
11-24-2004, 10:39 PM
hi guys,
i seem to have a problem here. you see i need to execute a php script to execute a shell script which contains the useradd function. however hard i've tried the shell script would'nt work. Btw i'm working on a mandrake machine. heres the script pls help!

php script
-------------

<?php
$output = shell_exec("heavenAdd $username $password") ;
echo "<pre>$output</pre>";
echo "testing"
?>

shell script
---------------
if [ "$(whoami)" != "root" ] ; then
echo "Error: You must be root to run this command." >&2
exit 1
fi
if [ "$1" = "" ] ; then
echo "You must key in your username as first argument and password as second argument"
exit 1
elif [ "$2" = "" ] ; then
echo "you must key in your password as second argument"
exit 1
fi
adduser $1
echo $2 > passwdfile
passwd --stdin $1 < passwdfile
rm -rf passwdfile

tjeonnybravo
11-24-2004, 11:32 PM
errm sorry this shuld be the right code for the shell script

shell script
-------------
if [ "$1" = "" ] ; then
echo "You must key in your username as first argument and password as second argument"
exit 1
elif [ "$2" = "" ] ; then
echo "you must key in your password as second argument"
exit 1
fi
adduser $1
echo $2 > passwdfile
passwd --stdin $1 < passwdfile
rm -rf passwdfile