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.

thanks

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:
$UADD (USERNAME)

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

PATH=$PATH:/usr/sbin:/usr/bin
export PATH

Hope it's working soon :)

, Mike

thanks for all your help i have completed the script using variables.

thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.