RE: useradd results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 

> -----Original Message-----
> From: redhat-list-bounces@xxxxxxxxxx 
> [mailto:redhat-list-bounces@xxxxxxxxxx] On Behalf Of Muhammad Rizwan
> Sent: Saturday, March 12, 2005 9:04 AM
> To: redhat-list@xxxxxxxxxx
> 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@xxxxxxxxxx?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

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux