1

I have this phpscript that passes arguments to a .sh script like:

$command = shell_exec("sudo ./createclientcert.sh $uniqcertid $number $period $userName $userPass");

The username should be checked to see if it not already exists. Normally when issuing the command via the terminal you' ll get

useradd: user 'newusername' already exists

How in the sh should i test that condition and abort the script and that it returns something meaningful for the calling php page to respond to?

The sh receives the arguments like:

newclient "$1" "$2" "$3" "$4" "$5"

newclient () {
# Generates the custom client.ovpn
useradd $4    
echo $4:$5 | chpasswd
#some other things but not relevant to the question
}

marked as duplicate and then referring to a solution using something like getent? It's not possible to capture the output useradd generates when the username already exists?

  • make a command $test = shell_exec("ls"); print_r($test); whats the result? – Rafael Shkembi Dec 09 '16 at 13:44
  • I really don' t understand what you mean by this suggestion. Shell_exec is working fine and listing a dir is not what i want. In the script the useradd command is issued and it needs to halt if the user already exists and return something meaningful. – Ingrid Lambrechtse Dec 09 '16 at 13:52
  • 1
    Managed to get it to work with the solution provided by tripleee . http://stackoverflow.com/questions/14810684/check-whether-a-user-exists Thnx. – Ingrid Lambrechtse Dec 10 '16 at 09:22

0 Answers0