Operating System - Linux
1748198 Members
2580 Online
108759 Solutions
New Discussion юеВ

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

 
roofalison
New Member

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

don't use the standard command useradd.
thanks so much.
3 REPLIES 3
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
Jon Gomersall
Advisor

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