Koozali.org: home of the SME Server
Legacy Forums => Experienced User Forum => Topic started by: David O'Dwyer on February 23, 2001, 01:42:22 AM
-
Hi.
Just a short question here.
Is it possible to add a batch of users (or more like 900 users :) from a textfile?
As I work for a school i need the facility to add/remove large quantites of users without too much hassle.
Thanks for your time
David
-
Yes, it is possible. User account data is stored in /home/e-smith/accounts. The records resemble:
username=user|property|value...
The property|value pairs repeat. Take a look at the file, you'll be able to figure out the structure of the user entries easy enough.
Here are the relevant commands from a script I use to auto-create users. Data you will need to supply is in all upper case (see note below regarding EmailForward property, though.) If you already have the info for you 900+ users in a text file, you can either write a script to read that file and call these commands in a function, or you can read the text file and create a monolithic script with 900+ instances of these commands.
----------
/sbin/e-smith/db accounts set USERNAME user City 'CITY, STATE POSTCODE' FirstName FIRSTNAME Phone '(555) 555-5555' ForwardAddress 'LEAVE BLANK OR ENTER FWD ADDRESS' EmailForward forward Dept DEPTNAME LastName LASTNAME PasswordSet no Company 'MY COMPANY NAME' Street 'MY STREE ADDRESS'
/sbin/e-smith/signal-event user-create USERNAME
perl -e "use esmith::util; esmith::util::setUserPassword ( 'USERNAME', 'PASSWORD' );"
/sbin/e-smith/db accounts setprop USERNAME PasswordSet yes
----------
Note the use of ' ' to enclose strings which contain spaces and other special characters. The perl command is a one-liner. The options for EmailForward are:
local = deliver email locally
forward = forward to the address in ForwardAddress
both = deliver locally and forward to ForwardAddress
I've found it handy to introduce a 1-2 second sleep between each iteration of the above commands. In particular, without the sleep the password setting routines seem to have problems. In my script I call each command for all users before executing the next command -- that is, I'll create the entries in accounts for all users, then signal the user-create event for all users, then create the password, then set the PasswordSet flag. In the password setting loop, if I don't introduce the sleep then some of the passwords will not get set. With even a sleep 1, they will all succeed. Go figure.
Good luck!
-
I should add that the preceding example is based on the 4.0 version. You may (or may not) need to make adjustments for 4.1
-
Thank you very much!
I tried the command and they work up until i get to:
perl -e "use esmith::util; esmith::util::setUserPassword ( 'USERNAME', 'PASSWORD' );"
Where i get:
Failed to set Unix password for account ****
again thanks for your help.
David
-
You're welcome. I'm assuming you are running these commands as root, right?
If double-checked the syntax (shown again below) which works a charm for me.
perl -e "use esmith::util;
esmith::util::setUserPassword ( 'USERNAME', 'PASSWORD' ) ;"
Note that you can break the perl script onto two lines if you'd prefer. One should work fine, though.
Double-check /etc/passwd to ensure that the users are in fact being created. It may be that the user-create event is failing, which might be because your accounts records have a flaw, etc.
-
hello again
To answer your question earlier i am running 4.1
I checked the /etc/passwd file and it doesnt seem like the users are being added :(
is it possible for u to paste ur exact scipt for me to have a look?
David
-
I don't think so as it is spread across several scripts; however, I tried the code I provided earlier and it works fine.
The difference is likely between 4.0 and 4.1 -- maybe someone else can shed some light on any differences. Until then, you might have a look at the perl scripts that create users (both the event and web function code) for clues.
As I don't have a 4.1 system up and running at the moment, I can't give you much more than that. Sorry.
-
Thanks alot for your help it is most appreciated
Where would i find the code to sift through?
Would it be possible to discuss this further? (iRC....)
David
-
Unless 4.1 is substantially changed, the places to look are:
/etc/e-smith/events -- this is where the code that signal-events runs lives
/etc/e-smith/web/functions -- these are the scripts for the web manager
-
Success! kind of :)
it seems the db accounts command line needed a GID & UID. i can add users now. and change their password. problem is they dont seem to be able to log into webmail which is the primary reason for me using this system :(
Oh hum. here we go again :)
David
-
That's good. I figured there would be differences from 4.0 to 4.1.
For the webmail thing -- which I haven't looked at, so this is a guess -- there is probably some flag set elsewhere. Does 4.1 ask who does and does not have webmail access, or is it a generic everybody or nobody approach? If the former, then you should look at the code for that web manager panel, which should direct you towards the solution.
-
No worries got it working now :)
Thank you for your help.
David
-
That's good news, and you are most welcome.
You should post the solution for 4.1 back to the forum so the next guy (which might be me -- I'll have to move to 4.1 eventually!) can be helped as you were.