quota update script

Nicolas KOWALSKI Nicolas.Kowalski at imag.fr
Wed Nov 16 09:40:08 EST 2005


On Wed, 16 Nov 2005, Bartosz Jozwiak wrote:

> Hi guys,

Hello,

> I am running Cyrus IMAP for sometime right now.
> We have around 2000 users. I will like to upgrade
> quota for each user.
> Does anybody has a script which could do it fast?
> Any hints would be much then appreciated.

I wrote the following one for setting up quotas in batch. 

Hope this helps.


#!/usr/bin/perl

#
# USAGE: cyrus-setquota <quota-in-bytes>
# logins are read from STDIN, one per line
# if <quotas-in-bytes> is 'none', remove the quota limit
#

$server = "localhost";
$port = 143;
$mech = "PLAIN";
$auth = "cyrus";
$pw = "<cyrus-password-here>";
$separator = "/";		# set this to "." if not using unixhierarchysep

use Cyrus::IMAP::Admin;


#
# Connect to server
#
$cyradm = Cyrus::IMAP::Admin->new($server, $port)
      or die "cyradm: cannot connect to server\n";

$cyradm->authenticate(-user => $auth,
                      -mechanism => $mech, 
                      -password => $pw)
    or die "cyradm: cannot authenticate to server" 
	   . (defined($mech) ? " with mech $mech" : "") 
	   . " as user $auth\n";


#
# quota to setup
#
$setthisquota = $ARGV[0];
if ($setthisquota eq '') {
        $setthisquota = 'none';
}


#
# read logins, apply quota
#
while (<STDIN>) {
        chomp;
        my $mailbox = "user".$separator."$_";
        print "Setting quota on $mailbox";
        if ($setthisquota ne 'none' ) {
                $cyradm->setquota($mailbox, "STORAGE", $setthisquota);
        } else {
                $cyradm->setquota($mailbox);
        }
        print "Done\n";
}



-- 
Nicolas



More information about the Info-cyrus mailing list