[wplug] Script help again
Duncan Hutty
dhutty+wplug at ece.cmu.edu
Mon Aug 14 17:15:21 EDT 2006
Gentgeen wrote:
>
> This year, I am setting up a wiki (DokuWiki) as our "teachers toolbox".
> I have everything set, but no I need to add some 100+ teachers to the
> authenication file. And since Doku does not have a "batch" add, I am
> hoping I can do it by a script instead of added each one by hand.
>
> I currently have a CSV sheet with all necessary info, except the
> password. The password has to be an md5sum has.
>
> So right now my CSV sheet looks something like this:
>
> username,password,RealName,email,roll
> admin,,Admin,ksquire at pavcs.org,admin
>
> I know that "echo -n PASSWORD | md5sum" will output the password to the
> command line.
>
> The password and the username will be the same for inital login, so I
> just need to get column 1 read to md5sum, and then have that output
> written to column 2. Then repeat until it gets to the end of the file.
> The only spaces in the file would be in the "Real Name" section (if that
> helps any).
>
> the DokuWiki User file uses the same format, except the commas are
> colons, but that part I can get :-)
>
> Anyone?
>
> I thank you in advance for your time.
>
>
There are lots of ways to do this.
perl has a nice little module. Here are the important bits.
Add your own command line option management, input validity checking, etc.
use Digest::MD5;
open(INFILE,$infile);
open(OUTFILE,>$outfile);
while (<INFILE>) {
($username,$password,$realname,$email,$roll) = split(/,/);
$md5 = md5($password);
$output = "${username}:${md5}:${realname}:${email}:${roll}\n";
print OUTFILE $output;
}
--
Duncan Hutty
More information about the wplug
mailing list