On Wed, Dec 12, 2001 at 01:56:40PM -0800, Richard Pruitt <[EMAIL PROTECTED]> wrote:
| I have written a script that allows my admins to add a user to our SFTP server. I
|have one problem:
| How do I verify if a user already exists?
|
| I have this, but it gives me unary error when the user doesn't exist because it
|doens't output a numeric value.
|
| #!/bin/sh
|
| echo -n "What is the username?"
I like to put a space after the prompt...
| read var1
|
| var2=`/usr/bin/id -u $var1`
You want to test for id failing:
if var2=`id -i "$var1"`
then
user exists ...
else
user doesn't exist ...
fi
And _always_ quote when dealing with values you've not made yourself - they
could be empty (your case) or have spaces of other undesirable stuff.
And don't use full paths for commands except in the most rare circumstances;
instead make sure your environment is suitably set up.
--
Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/
Death is life's way of telling you you've been fired. - R. Geis
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list