Bulk Provisioning

Revision as of 13:33, 31 July 2006 by MergeSpamAccountsIntoMe (talk | contribs) (Generating zmprov bulk input from CSV)

Generating zmprov bulk input from CSV

Following is a simple perl script to take a CSV file and turn it into the correct zmprov commands

#!/usr/bin/perl
 
# Lookup the valid COS (Class of Service) ID in the interface
# TODO: Find a way to map this automatically from the name rather than ID
my $cosid = "fd7ec8fc-069f-1111-1111-1111";
 
while (<>) {
       chomp;
 
       # CHANGE ME: To the actual fields you use in your CSV file
       my ($email, $password, $first, $last) = split(/\,/, $_, 4);
         
       my ($uid, $domain) = split(/@/, $email, 2);
 
       print qq{ca $uid\@$domain $password\n};
       print qq{ma $uid\@$domain zimbraCOSid "$cosid"\n};
       print qq{ma $uid\@$domain givenName "$first"\n};
       print qq{ma $uid\@$domain sn "$last"\n};
       print qq{ma $uid\@$domain cn "$uid"\n};
       print qq{ma $uid\@$domain displayName "$first $last"\n};
       print qq{ma $uid\@$domain zimbraPasswordMustChange TRUE\n};
       print qq{\n};
}

The above is only a starting place, you will need to change other options (eg: the zimbraPasswordMustChange is an example only) and of course how you create and split the input data.

Also, some CSV files may contain quotes you want to remove.

To execute use:

 perl csv2zmprov < mydata.csv > mydata.zmp
 zmprov < mydata.zmp

Enjoy

Jump to: navigation, search