Difference between revisions of "Bulk Provisioning"

(Generating zmprov bulk input from CSV)
(add passwd2zmprov, reformat, add category)
Line 1: Line 1:
= Generating zmprov bulk input from CSV =
+
[[Category:Migration]]
 +
 
 +
= Zmprov Command Files =
 +
 
 +
The zmprov command will accept commands from a file.
 +
Just pass the commands in on standard input like this:
 +
 
 +
  zmprov < mydata.zmp
 +
 
 +
Below are some ways to create a command file from your existing account data.
 +
 
 +
= Passwd File to Zmprov =
 +
 
 +
Following is a perl script to take a passwd file and turn it into a zmprov command file for account provisioning.
 +
 
 +
<pre>
 +
#!/usr/bin/perl
 +
################################################################################
 +
# $Id: passwd2zmprov,v 1.1.1.1 2007/01/23 18:04:38 dlbewley Exp $
 +
#-------------------------------------------------------------------------------
 +
# Description:
 +
#  Tool to create commands suitable for zmprov from a unix passwd file.
 +
#  We don't use getpwent etc., because we are likely working on a copy.
 +
#
 +
# See Also:
 +
#  http://wiki.zimbra.com/index.php?title=Bulk_Create
 +
#
 +
# Usage:
 +
#    ./passwd2zmprov /etc/passwd > users.zmp
 +
#    zmprov < users.zmp
 +
################################################################################
 +
 
 +
my $DOMAIN='hostname.foo.bar'; # zimbra installation domain name
 +
my $MIN_UID=500;  # skip system accounts like httpd
 +
my $MAX_UID=5000; # skip other system accounts like nfsnobody
 +
my $PASSWORD='password'; # default password
 +
# Zimbra Class Of Service for users
 +
my $COS_ID = 'e00000a0-0c00-00d0-000a-000d00afea0a'; # use during testing only
 +
#my $COS_ID = `su - zimbra -c 'zmprov gc Default |grep zimbraId:'`;
 +
#$COS_ID =~ s/zimbraId:\s*|\s*$//g;
 +
 
 +
 
 +
while(<>) {
 +
    chomp;
 +
    my ($uname,$x,$uid,$gid,$gecos) = split(/:/);
 +
    if (! ($MIN_UID < $uid && $uid < $MAX_UID)) {
 +
        warn "skipping $uname, $uid not between $MIN_UID and $MAX_UID";
 +
        next;
 +
    }
 +
 
 +
    my $date = localtime(time);
 +
    my ($fullname,$description) = split(/\s*,\s*/,$gecos,2);
 +
    my ($fname,$initial,$lname) = split(/\s+/,$fullname);
 +
    if (! $lname) {
 +
        $lname = $initial;
 +
        undef $initial;
 +
    }
 +
    my $displayname = "$fname $initial $lname";
 +
    $displayname =~ s/\s+/ /;
 +
 
 +
    print qq{ca $uname\@$DOMAIN "$PASSWORD"\n};
 +
    print qq{ma $uname\@$DOMAIN zimbraCOSid "$COS_ID"\n};
 +
    print qq{ma $uname\@$DOMAIN givenName "$fname"\n};
 +
    print qq{ma $uname\@$DOMAIN sn "$lname"\n};
 +
    print qq{ma $uname\@$DOMAIN cn "$uname"\n};
 +
    print qq{ma $uname\@$DOMAIN displayName "$displayname"\n};
 +
    print qq{ma $uname\@$DOMAIN description "$description"\n};
 +
    print qq{ma $uname\@$DOMAIN zimbraNotes "Migrated $date"\n};
 +
    print qq{ma $uname\@$DOMAIN zimbraPasswordMustChange TRUE\n};
 +
    print qq{\n};
 +
}
 +
</pre>
 +
 
 +
To execute:
 +
 
 +
  perl passwd2zmprov < passwd > mydata.zmp
 +
 
 +
= CSV File to Zmprov =
  
 
Following is a simple perl script to take a CSV file and turn it into the correct zmprov commands
 
Following is a simple perl script to take a CSV file and turn it into the correct zmprov commands
Line 5: Line 82:
 
  #!/usr/bin/perl
 
  #!/usr/bin/perl
 
    
 
    
  # Lookup the valid COS (Class of Service) ID in the interface
+
  # Lookup the valid COS (Class of Service) ID in the interface or like this
# TODO: Find a way to map this automatically from the name rather than ID
+
  my $cosid = `su - zimbra -c 'zmprov gc Default |grep zimbraId:'`;
  my $cosid = "fd7ec8fc-069f-1111-1111-1111";
+
$cosid =~ s/zimbraId:\s*|\s*$//g;
 
+
 
 
  while (<>) {
 
  while (<>) {
 
         chomp;
 
         chomp;
Line 31: Line 108:
 
Also, some CSV files may contain quotes you want to remove.
 
Also, some CSV files may contain quotes you want to remove.
  
To execute use:  
+
To execute:  
  
 
   perl csv2zmprov < mydata.csv > mydata.zmp
 
   perl csv2zmprov < mydata.csv > mydata.zmp
  zmprov < mydata.zmp
 
 
Enjoy
 

Revision as of 19:33, 23 January 2007


Zmprov Command Files

The zmprov command will accept commands from a file. Just pass the commands in on standard input like this:

 zmprov < mydata.zmp

Below are some ways to create a command file from your existing account data.

Passwd File to Zmprov

Following is a perl script to take a passwd file and turn it into a zmprov command file for account provisioning.

#!/usr/bin/perl
################################################################################
# $Id: passwd2zmprov,v 1.1.1.1 2007/01/23 18:04:38 dlbewley Exp $
#-------------------------------------------------------------------------------
# Description:
#   Tool to create commands suitable for zmprov from a unix passwd file.
#   We don't use getpwent etc., because we are likely working on a copy.
#
# See Also:
#   http://wiki.zimbra.com/index.php?title=Bulk_Create
#
# Usage:
#    ./passwd2zmprov /etc/passwd > users.zmp
#    zmprov < users.zmp
################################################################################

my $DOMAIN='hostname.foo.bar'; # zimbra installation domain name
my $MIN_UID=500;  # skip system accounts like httpd
my $MAX_UID=5000; # skip other system accounts like nfsnobody
my $PASSWORD='password'; # default password
# Zimbra Class Of Service for users
my $COS_ID = 'e00000a0-0c00-00d0-000a-000d00afea0a'; # use during testing only
#my $COS_ID = `su - zimbra -c 'zmprov gc Default |grep zimbraId:'`;
#$COS_ID =~ s/zimbraId:\s*|\s*$//g;


while(<>) {
    chomp;
    my ($uname,$x,$uid,$gid,$gecos) = split(/:/);
    if (! ($MIN_UID < $uid && $uid < $MAX_UID)) {
        warn "skipping $uname, $uid not between $MIN_UID and $MAX_UID";
        next;
    }

    my $date = localtime(time);
    my ($fullname,$description) = split(/\s*,\s*/,$gecos,2);
    my ($fname,$initial,$lname) = split(/\s+/,$fullname);
    if (! $lname) {
        $lname = $initial;
        undef $initial;
    }
    my $displayname = "$fname $initial $lname";
    $displayname =~ s/\s+/ /;

    print qq{ca $uname\@$DOMAIN "$PASSWORD"\n};
    print qq{ma $uname\@$DOMAIN zimbraCOSid "$COS_ID"\n};
    print qq{ma $uname\@$DOMAIN givenName "$fname"\n};
    print qq{ma $uname\@$DOMAIN sn "$lname"\n};
    print qq{ma $uname\@$DOMAIN cn "$uname"\n};
    print qq{ma $uname\@$DOMAIN displayName "$displayname"\n};
    print qq{ma $uname\@$DOMAIN description "$description"\n};
    print qq{ma $uname\@$DOMAIN zimbraNotes "Migrated $date"\n};
    print qq{ma $uname\@$DOMAIN zimbraPasswordMustChange TRUE\n};
    print qq{\n};
}

To execute:

 perl passwd2zmprov < passwd > mydata.zmp

CSV File to Zmprov

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 or like this
my $cosid = `su - zimbra -c 'zmprov gc Default |grep zimbraId:'`;
$cosid =~ s/zimbraId:\s*|\s*$//g;
  
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:

 perl csv2zmprov < mydata.csv > mydata.zmp
Jump to: navigation, search