General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a "useradd" bash program for me?

roofalison
Occasional Visitor

How to write a "useradd" bash program for me?

don't use the standard command useradd.
thanks so much.
3 REPLIES
Patrick Terlisten
Honored Contributor

Re: How to write a "useradd" bash program for me?

Hello,

why don't you want to use the standard program?? If you need to add useraccounts, but won't using "useradd", write a simple script. With a combination of "echo", "sed" and "awk" you can add or change lines to /etc/passwd and /etc/group. With "mkdir" you can create home directories, with "cp" you can copy files vom /etc/skel to the new created home directory. Don't forget to change the ownership and permission while using "chown" and "chmod".

Best regards,
Patrick
Best regards,
Patrick
Alan_152
Honored Contributor

Re: How to write a "useradd" bash program for me?

This sounds suspiciously like a homework question one of my fellow instructors likes to assign to his scripting class.

Anyhow, the trick here to start is to build a script that will accept various arguments. Then take each argument and put them into an echo line something like this:

echo $1:x:$2:$3:$4:$5:$6 >> /etc/passwd

where 1 is the username, 2 is the UID, 3 is the GID, 4 is the LYCOS field, 5 is the root path, and 6 is the startup shell.

You would then enter something like this at your command line:

$ ./myscript username 222 333 stuff /home/username /sbin/sh

And, if everything works right (this example probably has a few tweaks in it that need fixing), the last line of the password file should look like this:

username:x:222:333:stuff:/:/sbin/sh

Re: How to write a "useradd" bash program for me?

within redhat you can use a utility called

newusers

Go to the following link to see how it works

http://kbase.redhat.com/faq/FAQ_43_4400.shtm