useradd results
Michael Velez
mikev777 at hotmail.com
Sat Mar 12 15:48:25 UTC 2005
> -----Original Message-----
> From: redhat-list-bounces at redhat.com
> [mailto:redhat-list-bounces at redhat.com] On Behalf Of Muhammad Rizwan
> Sent: Saturday, March 12, 2005 9:04 AM
> To: redhat-list at redhat.com
> Subject: useradd results
>
> Hello
>
> Is there any way to get the results of useradd command. Means
> if i run useradd command through shell script or c code, then
> is there any way to get the nessage return by command in program.
>
> Any idea?
>
> Thanks
>
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
>
There are several ways to capture output from a command in a shell script.
If you want to capture the return value, you can use the $? variable, which
will return the return value of the last command executed. For example, the
return value would be 0 if the command executes successfully, 6 if the user
already exists, and 3 if you have specified a bad username. I don't know
the return value for other error situations.
If you're looking to capture any return message that useradd generates, you
could either use the grave accents: ` ` or pipe the output to another
command.
Example using the $? Variable:
useradd ...
if [[ $? = 0 ]]
then
echo "useradd: command completed successfully"
fi
Example using grave accents:
RETURNVARIABLE=`useradd ...`
Example using pipes
useradd ... | awk ...
useradd ... | sed ...
I think this version of useradd only returns error messages so there is no
point in piping to awk or sed. Would verifying the return value with $?
Satisfy what you're doing?
Hope this helps,
Michael
More information about the redhat-list
mailing list