I am attempting to write a script that will add a user to the system. I am using fedora 5 and am attempting to use the useradd: command but i receive "command not found" I am also trying to get the current users from the system so i can check if the user is already there.

any help with this is greatly appreciated.


10 Years
Discussion Span
Last Post by ProfessorPC

Hey there,

useradd is probably just not in your path. To safeguard against that error in your script, use a fully qualified path, like:

/usr/bin/useradd - or /usr/sbin/useradd (It's one of those two on Fedora, I believe)

You can check what user already exist on the system by just using awk to pull the usernames from /etc/passwd and then testing against that:

awk -F":" '{print $1}'

then write your script to compare against all those names.

Hope that helps :)

, Mike


Alternatively, you can make a variable
UADD="$(which useradd)"
Then in the script, just put useradd command like this:


Hey there,

The variable is a good idea. Should make your code tighter.

Just be sure that useradd is in your PATH or "which" will give you the same error (not found).

I'm not sure what shell you're using (hence the old-style "export" below) or what your PATH variable resolves to now, but this will probably fix the problem for you if you add it to your .profile, .bashrc or run it off the command line, etc

export PATH

Hope it's working soon :)

, Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.