PDA

View Full Version : Batch create users



monkey
24th February 2004, 04:10 AM
After using newusers to batch create users with their passwords, say user01, user02, user03. I would like to know how can copy the startup scripts from /etc/skel to their home directories?
Because I have tried to use:

cp /etc/skel/* /home/user[1-3]
But seems not working. Can I use cp to do that? Or I can only use scripts to do so?
Thanks in advance.

DaDevil
24th February 2004, 04:37 AM
All the files in the /etc/skel/ directory are hidden. Meaning they start with a "." .

So issuing the command

cp /etc/skel/* /home/test/

will result in
cp: cannot stat `/etc/skel/*': No such file or directory

So you can issue cp -R /etc/skel/.* /desired/path

Wait Wait do not run off to issue this command because if you do it you will discover that your whole goddamn /etc directory now resides in your /desired/path. :D

This is because of the ".." in every dir denoting the parent which unfortunately in this case is /etc/.

So the solution is

cp -R /etc/skel/.[a-z]* /desired/path

Note the "." after /skel/

Or better yet just copy them over individually by hand there are only a few of them. Just a question why do you need to copy them manually ? Won't newusers do that for you. Or am i mistaken in this? Since I am not so familiar with newusers.

monkey
24th February 2004, 05:12 AM
Thanks DaDevil,

I found that when I use /home/user[1-3] as destination in cp command, the cp command will only do ONE set of copy for me, so if I have 3 users just like the above question - user01, user02, user03, only user03 will have those startup scripts in his home dir.

By the way, I have tried newusers, but what it has created for me is the user accounts (lines in /etc/passwd, corresponding lines in /etc/shadow) , their password and their home directories. It didn't copy the startup scripts for me. So is there any argument in newusers to do that? Am I missing something? Thanks.

mhelios
24th February 2004, 05:26 AM
monkey,

I realise you said you want to automate the process of adding multiple users, but FYI the `useradd` command will automatically copy the contents of /etc/skel to each new users home directory.

monkey
25th February 2004, 04:56 AM
Thanks ... the `useradd` command will copy the startup scripts for me, then can I use useradd to create a batch of users? because I don't know how, and I can only add one per time.