ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Soon I will be asked to add multiple users on our Linux server, I will have a text file with a 30 names, I need a script that will add the 30 users+permission, can anyone help me or guide me to that, also what about the permission, can the permission be input from the text file, Thanks for your help.
What's the format of the names file? You'll need to know the name you want to use as the user's ID (the name they'll login with, and (not essential) their full name for the GECOS (comment) field. Your script can read the information from the name file with code like
cat namefile | while read user
# do the useradd
man useradd to see what you have to specify to create the user entry. Use $user for the ID of the user you're adding.
As to permissions, you can use chmod to change that if you're not happy with the defaults - you can refer to the user's home directory as ~username so you don't need to know the actual home directory path.
ok this is what i did, new text file and saved as users.sh
cat names | while read first last user
# do the useradd
/usr/sbin/useradd -c "$first $last" -m $user
i run the scpript i did
cat /etc/passwd | cut -d ":" -f1
and the new user was added + $Home.
but i still have problem understanding this line:
while read first last user
last and user are just simple text how does the system knows that first would be the name of the user...etc!! am just trying to understand, and $first $last $user are dynamic var?, how they are connected with first last and user, what am trying to say how does the system knows the order of content of the file?
when i tried adding more users on my text it would only add the first line
test test1 test2
alex alex1 alex2
only test2 will be added!