From: Jamie C. <jca...@we...> - 2006-08-22 17:53:57
|
On 22/Aug/2006 08:53 Carlton Thomas wrote .. > > Hi, > > I need to migrate some users from an old UNIX system to a > Linux box. Since I need to do a number of operations, eg. > copy user files, I have decided to write a Perl script to > automate the task. To simplify things and to take advantage > of some of Webmin's functionality, I would like to have my > script call the Webmin "save_user.cgi" script to add the > users to the Linux box. > > My script will run on the Linux box and do the following:- > > 1) read a line from the password file > > 2) parse the line to extract things like username, enc_password > > 3) call Webmin's "save_user.cgi" to add new user to linux box > > 4) rcp user's files from old box to new directories on Linux box > > 5) chown and chgrp user's files > > Is it feasible (or even possible) to use the Webmin module in this > way? If it is possible, what do I need to do to ensure that the > Webmin script will run correctly, eg. setting environment variables. Yes, you could use a command-line program that calls Webmin functions to do this. I would recommend putting it in the base directory (typically /usr/libexec/webmin), and coding it like : #!/usr/bin/perl $no_acl_check++; $ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin"; $ENV{'WEBMIN_VAR'} ||= "/var/webmin"; if ($0 =~ /^(.*\/)[^\/]+$/) { chdir($1); } chop($pwd = `pwd`); $0 = "$pwd/create-users.pl"; require './web-lib-lib.pl'; $< == 0 || die "create-users.pl must be run as root"; &foreign_require("useradmin", "user-lib.pl"); &useradmin::making_changes(); while(<STDIN>) { # Parse user and create object $user = { ... }; &useradmin::create_user($user); } &useradmin::made_changes(); - Jamie |