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?