add multiple users(Script)
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.
|
while searching i found this
http://www.linuxquestions.org/questi...hreadid=352419 but i couldnt really understand how does it work. |
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
Code:
cat namefile | while read user 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. Have a go and ask again if you get stuck. |
what am thinking of sth like this:
file allusres.txt firstname lastname username . . . . . . .20 times. |
how about when you've read the line,
Code:
echo $line | sed 's/ /\n/g' | { read first; read last; read user; }; hth --Jonas |
Quote:
Code:
cat namefile | while read first last user |
Much better :-)
You know, those manuals don't seem so silly after all :D. --Jonas |
Quote:
how does the while works, the first last user how would be recognized? sorry am just new into this? |
first, last and user are each seperated by a character in $IFS (`Internal Field Seperator' or similar).
try Code:
$ IFS='x' btw, couldn't one also do "while ... done < namefile" instead of catting? |
ok this is what i did, new text file and saved as users.sh
Code:
cat /etc/passwd | cut -d ":" -f1 and the new user was added + $Home. but i still have problem understanding this line: Code:
//edit 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! Thanks. |
Quote:
The system `knows' that it's the first-/last-/username of the new user, because useradd expects them to be in particular places and the script puts them the right places (see man useradd). hth --Jonas |
thanks jonaskoelker for your time, but why the loop does not go to the next line?
|
One guess: does the file end in a newline character? It has to; otherwise read won't read the last item. Try a file with more than two items.
hth --Jonas |
ok lets say this is my file:
test test1 test2 alex alex2 alex3 win win1 win2 the system will only add the win2! not really sure why this happening!! |
Weird--first it only adds the first user, then only the last user.
Might it be that some of the users were already added? Try replacing the loop body with echo. hth --Jonas |
All times are GMT -5. The time now is 07:36 PM. |