Schools in NSW use an administration and student records system called OASIS. For schools that are implementing Linux or UNIX servers, it is important to be able to create student and staff accounts automatically.
This Perl script imports data from an OASIS report file and writes it out in a format which can be imported with the Webmin administration interface.
Usage:
./psa.pl < report-file > batch-import-file Here is the script: #!/usr/bin/perl # $Id: psa.pl,v 1.4 2003/07/06 02:43:40 les Exp $ # Process an OASIS report file containing student data to create a # Webmin batch input file # Format of input lines: # Year number, SURNAME, firstname, sex # Additional requirements: # watch for duplicates and deal with them # Customize defaults here $defpassword = "password"; # Kids in this year and later will be assigned a password; # those in earlier years will not - they just need their username to log on $passwordfrom = 3; # Set the default shell to /sbin/nologin if you want them to never # be able to work at the command line (Webmin will set their Samba password) $shell = "/bin/bash"; # The following can be left as empty strings if passwords # are not being expired # Minimum time after password change before the user can change it again $min = ""; # Maximum age a password can get to $max = ""; # Number of days before password expires that user will start getting # warnings $warn = ""; # Days after password expires that account will be disabled $inactive = ""; # Date when account is disabled (days since Jan 1, 1970) $expire = ""; # Set the input record separator to "\r", as that's what delimits # an OASIS report file (Yecch!) $/ = "\r"; # Skip over the header line $junk = <>; while (<>) { @fields = split(/,/, $_); ($year, $surname, $firstname, $sex) = @fields; $sex = chomp($sex); $lsurname = $surname; $firstname =~ s/^\s+//; $lfirstname = $firstname; $lsurname =~ tr/A-Z/a-z/; # Squeeze out any whitespace characters in the login surname $lsurname =~ s/\s//; # Strip out any apostrophes in the login surname $lsurname =~ s/\'//; $lfirstname =~ tr/A-Z/a-z/; $initial = substr($lfirstname,0,1); $username = $initial . $lsurname; if ($year >= $passwordfrom) { $password = $defpassword; } else { $password = ""; } print "create\:$username\:$password\:\:\:$firstname $surname, Year $year:/home/$username\:$shell\:$min\:$max\:$warn\:$inactive\:$expire\n"; # Comment out the previous line and uncomment this one # for deletion of test accounts # print "delete:$username\n"; } At the time of writing, the script has had minimal testing. It has been successfully used; however, I manually fixed up the batch import file in order to resolve a couple of duplicate usernames (got to watch for those jsmith's!) and clean up a couple of names which had apostrophes in them. A later version of this script will probably deal with those problems. Longer term, I expect to create scripts which will deal with LDAP accounts (using Net::LDAP) as that is our strategic direction.
#!/usr/bin/perl # $Id: psa.pl,v 1.4 2003/07/06 02:43:40 les Exp $ # Process an OASIS report file containing student data to create a # Webmin batch input file # Format of input lines: # Year number, SURNAME, firstname, sex # Additional requirements: # watch for duplicates and deal with them # Customize defaults here $defpassword = "password"; # Kids in this year and later will be assigned a password; # those in earlier years will not - they just need their username to log on $passwordfrom = 3; # Set the default shell to /sbin/nologin if you want them to never # be able to work at the command line (Webmin will set their Samba password) $shell = "/bin/bash"; # The following can be left as empty strings if passwords # are not being expired # Minimum time after password change before the user can change it again $min = ""; # Maximum age a password can get to $max = ""; # Number of days before password expires that user will start getting # warnings $warn = ""; # Days after password expires that account will be disabled $inactive = ""; # Date when account is disabled (days since Jan 1, 1970) $expire = ""; # Set the input record separator to "\r", as that's what delimits # an OASIS report file (Yecch!) $/ = "\r"; # Skip over the header line $junk = <>; while (<>) { @fields = split(/,/, $_); ($year, $surname, $firstname, $sex) = @fields; $sex = chomp($sex); $lsurname = $surname; $firstname =~ s/^\s+//; $lfirstname = $firstname; $lsurname =~ tr/A-Z/a-z/; # Squeeze out any whitespace characters in the login surname $lsurname =~ s/\s//; # Strip out any apostrophes in the login surname $lsurname =~ s/\'//; $lfirstname =~ tr/A-Z/a-z/; $initial = substr($lfirstname,0,1); $username = $initial . $lsurname; if ($year >= $passwordfrom) { $password = $defpassword; } else { $password = ""; } print "create\:$username\:$password\:\:\:$firstname $surname, Year $year:/home/$username\:$shell\:$min\:$max\:$warn\:$inactive\:$expire\n"; # Comment out the previous line and uncomment this one # for deletion of test accounts # print "delete:$username\n"; }
Importing into Webmin
Log into Webmin, the select the "System" tab at the top of the page, then the "Users and Groups" icon at the bottom of the page. Click on the "Create, modify and delete users from batch file" link and you will see the screen below:
The defaults should be fine in most cases. If you have the batch file on a floppy disk on a Windows PC where you are working, you can use the "Upload batch file" field and the adjacent "Browse" button to specify its location. If you already have it on the Linux server, then you should use the "..." button beside the "Local batch file" field (remember, you may have to mount the floppy disk first with the "mount /mnt/floppy" command and unmount it afterwards with the "umount /mnt/floppy" command),
Then click the "Execute batch" button and sit back and watch as hundreds of accounts are created.
If there are lots of problems and you need to delete accounts, you can comment out the print "create . . ." line at the end of the loop and uncomment the print "delete. . ." one then re-run the script to get a batch file which will delete the users you just created.
No warranty, express or implied. . .
RCS file: /var/local/cvsroot/sisp/psa.pl,v Working file: psa.pl head: 1.4 branch: locks: strict access list: symbolic names: START: 1.1.1.1 LBA: 1.1.1 keyword substitution: kv total revisions: 5; selected revisions: 5 description: ---------------------------- revision 1.4 date: 2003/07/06 02:43:40; author: les; state: Exp; lines: +41 -5 Added code to strip out apostrophes in login surnames. Added code to set passwords only for children in a certain year and above. Added defaults for shell and password expiry variables. ---------------------------- revision 1.3 date: 2003/07/02 07:15:26; author: les; state: Exp; lines: +4 -2 Fixed a bug in extraction of initial letter of first name. Fixed squashing of whitespace in surname (e.g. van jacobsen) ---------------------------- revision 1.2 date: 2003/07/02 07:01:13; author: les; state: Exp; lines: +3 -2 Added escaping of colons in output string so they do not mysteriously disappear after a variable name. Added a line to strip leading space before first name. ---------------------------- revision 1.1 date: 2003/07/02 06:40:16; author: les; state: Exp; branches: 1.1.1; Initial revision ---------------------------- revision 1.1.1.1 date: 2003/07/02 06:40:16; author: les; state: Exp; lines: +0 -0 Initial Import ============================================================================= Page last updated: 06/Jul/2003 Back to Home Copyright © 1987-2010 Les Bell and Associates Pty Ltd. All rights reserved. webmaster@lesbell.com.au