Archive | March, 2009

Alternate SMTP Port

Here’s a quick IPTables rule to setup an alternate non-standard SMTP port without reconfiguring the mail server software: /sbin/iptables -t nat -A PREROUTING -p tcp -m tcp –dport 2525 \ -j REDIRECT –to-ports 25 Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers Tweet about it Subscribe to the [...]

Here’s a quick IPTables rule to setup an alternate non-standard SMTP port without reconfiguring the mail server software:

/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 2525 \
-j REDIRECT --to-ports 25
View Comments Continue Reading →

SED Search / Replace Multiple Files

I’m a big fan of the “replace” utility included in the mysql client package. With this utility you can search/replace a string of text across multiple files like this: replace ‘from-string’ ‘to-string’ — start-folder/*.pl Quick and easy! But on occasion I’m on a system that doesn’t have the mysql client package so here’s a similar [...]

I’m a big fan of the “replace” utility included in the mysql client package. With this utility you can search/replace a string of text across multiple files like this:

replace 'from-string' 'to-string' -- start-folder/*.pl

Quick and easy!

But on occasion I’m on a system that doesn’t have the mysql client package so here’s a similar function using find and sed:

find start-folder/ -name '*.pl' -exec sed -iorig 's/from-string/to-string/' {} \;
View Comments Continue Reading →

Export Zimbra mailbox

To export the mailbox for user@acme.com as a zip file use this command: /opt/zimbra/bin/zmmailbox -z -m user@acme.com getRestURL \ ‘//?fmt=zip&query=is:anywhere’ > user_at_acme_com.zip Here is the same as a tgz file: /opt/zimbra/bin/zmmailbox -z -m user@domain.com getRestURL \ “//?fmt=tgz” > /tmp/account.tgz And here’s a restore of the tgz file: /opt/zimbra/bin/zmmailbox -z -m user@domain.com postRestURL \ “//?fmt=tgz&resolve=reset” /tmp/account.tgz [...]

To export the mailbox for user@acme.com as a zip file use this command:

/opt/zimbra/bin/zmmailbox -z -m user@acme.com getRestURL \
‘//?fmt=zip&query=is:anywhere’ > user_at_acme_com.zip

Here is the same as a tgz file:

/opt/zimbra/bin/zmmailbox -z -m user@domain.com getRestURL \
“//?fmt=tgz” > /tmp/account.tgz

And here’s a restore of the tgz file:

/opt/zimbra/bin/zmmailbox -z -m user@domain.com postRestURL \
“//?fmt=tgz&resolve=reset” /tmp/account.tgz

View Comments Continue Reading →

Zimbra Mailbox Size

Here’s a simple script that will provide a report on mailbox size for every mailbox on a Zimbra server. The report is sorted by box size in descending order: #!/usr/bin/perl my $all_accounts=`zmprov gaa`; my @accounts = split(/\n/,$all_accounts); my @sizes; foreach $account (@accounts) { my $mb_size=`zmmailbox -z -m $account gms`; chomp($mb_size); my $size; if ($mb_size =~ [...]

Here’s a simple script that will provide a report on mailbox size for every mailbox on a Zimbra server. The report is sorted by box size in descending order:

#!/usr/bin/perl

my $all_accounts=`zmprov gaa`;
my @accounts = split(/\n/,$all_accounts);

my @sizes;
foreach $account (@accounts) {
    my $mb_size=`zmmailbox -z -m $account gms`;
    chomp($mb_size);
    my $size;
    if ($mb_size =~ /(.+)\ GB/) {
        $size = $1 * 1024 * 1024;
    } elsif ($mb_size =~ /(.+)\ MB/) {
        $size = $1 * 1024;

    } elsif ($mb_size =~ /(.+)\ KB/) {

        $size = $1;
    } elsif ($mb_size =~ /(.+)\ B/) {
        $nsize = $1;
        if ($nsize eq 0) {
                $size = 0;
        } else {
                $size = abs(1024/$1);
        };
    };
    $next = scalar(@sizes);
    $sizes[$next][0] = $account;
    $sizes[$next][1] = $size;
};

@sizes = sort { $a->[1] <=> $b->[1] } @sizes;

my $D=`date +'%m/%d/%y %H:%M'`; chomp($D);

print "==========================================================\n";
print " Zimbra Mailbox Report\n";
print " \n";
print " All sizes in KB.";
print " Generated on: $D\n";
print "==========================================================\n";

for (my $i = $#sizes-1; $i >= 0; $i--) {
    printf ("%15.2f %s\n",$sizes[$i][1], $sizes[$i][0]);

};
View Comments Continue Reading →

Perl – Sorting multi-diminsional arrays

To numerically sort @myarray by the second column do this: @myarray = sort { $a->[1] $b->[1] } @myarray; Here is an alpha sort of @myarray on the third column: @myarray = sort { $a->[2] cmp $b->[2] } @myarray; Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers Tweet about [...]

To numerically sort @myarray by the second column do this:

@myarray = sort { $a->[1] <=> $b->[1] } @myarray;

Here is an alpha sort of @myarray on the third column:

@myarray = sort { $a->[2] cmp $b->[2] } @myarray;
View Comments Continue Reading →