Archives for: March 2009

03/30/09

Permalink 10:50:43 am, by admin Email , 54 words   English (US)
Categories: Apache

Activate GZIP compression in Apache

Create a file at /etc/httpd/conf.d/deflate.conf with the following contents:

SetOutputFilter DEFLATE

# Don't compress picture files
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \ no-gzip dont-vary

# Don't compress compressed files
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary

# Don't compress pdf's
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

03/26/09

Permalink 01:01:58 pm, by admin Email , 22 words   English (US)
Categories: Misc

Here Doc

A "here document" is a method for specifying a multi-line string literal in many programming languages. Here are some examples:

Perl
print <<"END";

MULTIPLE LINES OF TEXT HERE

END

PHP
echo <<<EOF

MULTIPLE LINES OF TEXT HERE

EOF;

Bash
cat << EOF

MULTIPLE LINES OF TEXT HERE

EOF
Permalink 10:52:32 am, by admin Email , 35 words   English (US)
Categories: PHP

PHP Mailer : Swift Mailer

Every time I need a PHP class to handle sending email I turn to Swift Mailer at:

http://swiftmailer.org.

It's feature rich and easy to use.

Only downside is it doesn't work for PHP4.

03/24/09

Permalink 08:36:42 am, by admin Email , 40 words   English (US)
Categories: Zimbra

Zimbra - Set MTA Trusted Networks From Command Line

To view trusted networks as the zimbra user:

/opt/zimbra/bin/zmprov gs {servername} zimbraMtaMyNetworks

To set trusted networks as the zimbra user do:

/opt/zimbra/bin/zmprov ms {servername} zimbraMtaMyNetworks {space delimited list of address and/or cidr ranges}

03/22/09

Permalink 03:54:42 pm, by admin Email , 38 words   English (US)
Categories: PHP

Alternate Install Method For PHP PECL Modules

If the traditional "pecl install APC" style command is not working for some reason, here is the manual procedure:

wget http://pecl.php.net/get/APC-3.0.19.tgz
tar -xvzf APC-3.0.19.tgz
cd APC-3.0.19
phpize
./configure
make
make install

Permalink 05:29:39 am, by admin Email , 122 words   English (US)
Categories: Misc

Find group writable home directories

With procmail, vacation and forward files do not work if the user's home directory is group writable. Here's a script that will locate all group writable home directories:

#!/usr/bin/perl

my %users;
open(P,"/etc/passwd");
while(

) {
chomp();
my ($uname,$pass,$uid,$gid,$gecos,$home,$shell) = split(/\:/,$_);
$users{$uname} = $home;
};
close P;

LINE: foreach $user (sort keys %users) {
$home = $users{$user};
next LINE if ($user eq "dbus");
next LINE if ($user eq "distcache");
next LINE if ($user eq "haldaemon");
next LINE if ($user eq "nobody");
next LINE if ($user eq "rpc");
$test = `find $home -maxdepth 0 -perm -g=w -type d 2>&1`;
chomp($test);
if ($test ne "") {
if ($test =~ /No such file or directory/) {
$msg = "NOT FOUND";
} else {
print $user . " : " . $home . "\n";
};
};
};

03/21/09

Permalink 08:50:02 pm, by admin Email , 88 words   English (US)
Categories: Project Gallery

vsftpd long username bug

Here's a patched source RPM for the vsftpd package included with RHEL5. It fixes this bug:

https://bugzilla.redhat.com/show_bug.cgi?id=486524

The bug limits user names to 32 characters. The patch raises the limit to 128 characters.

To build and install do:

rpm -i vsftpd-2.0.5-12longuser.src.rpm
rpmbuild -ba /usr/src/redhat/SPECS/vsftpd.spec
rpm -U /usr/src/redhat/SPECS/{ARCH}/vsftpd-2.0.5-12longuser.src.rpm

You can download the patched source file here:

http://blogs.reliablepenguin.com/files/vsftpd-2.0.5-12longuser.src.rpm

Permalink 08:18:01 pm, by admin Email , 30 words   English (US)
Categories: Project Gallery

Yum : Howto download source packages

First get the yum-utils package if you don't already have it:

yum install yum-utils

Next just do:

yumdownloader --source mypkg

where mypkg is the package that you want source for.

Permalink 03:59:57 pm, by admin Email , 71 words   English (US)
Categories: Misc

Perl - Sort associative array by value

Here's an alpha sort of the values of the associative array named "myarray":

foreach my $key (sort {$myarray{$a} cmp $myarray{$b}} keys %myarray) {
print "$key : " . $myarray{$key} . "\n";
};

And here's the same sort numerically:

foreach my $key (sort {$myarray{$a} <=> $myarray{$b}} keys %myarray) {
print "$key : " . $myarray{$key} . "\n";
};

And if you want numeric descending:

foreach my $key (sort {$myarray{$b} <=> $myarray{$a}} keys %myarray) {
print "$key : " . $myarray{$key} . "\n";
};

03/20/09

Permalink 05:14:47 am, by admin Email , 57 words   English (US)
Categories: Project Gallery

Encode/decode SMTP AUTH username/passwords

When using SMTP AUTH, the username and password are base64 encoded. Here's a snip of perl that will encode a string:

perl -MMIME::Base64 -e 'print encode_base64("username");'

This will produce something like this:

dXNlcm5hbWU=

And here's the decode:

perl -MMIME::Base64 -e 'print encode_base64("dXNlcm5hbWU=");'

which of course yields:

username

03/19/09

Permalink 11:23:25 am, by admin Email , 35 words   English (US)
Categories: MySQL

MySQL Binary Log Rotation

Came across a handy configuration setting for mysql:

expire_logs_days = 7

Controls how many days of binary log files should be retained. Very good way to keep the binary logs from over flowing available storage.

03/10/09

Permalink 06:05:23 am, by admin Email , 297 words   English (US)
Categories: General

Content Sync For Load Balancer With Unison

This Unison program is great. It neatly handles syncing between two servers where changes are occurring on both sides. On one client site it takes about 30 seconds to compare/sync a 23GB /var/www/html/ structure with about 100 sites.

1) Install unison (http://www.cis.upenn.edu/~bcpierce/unison/). Requires "ocaml" compiler (http://caml.inria.fr/), and needs the "etags" command from emacs (so "yum install emacs", whatever)

2) Set up a "/root/.unison/profile-name.prf" file. See example pasted below. Comment out "batch=true" and "silent=true" for initial test runs. Uncomment them for running from a cron job.

3) Run manually to test: unison profile-name

4) If you leave the logging turned on, make an /etc/logrotate.d/unison file, something like this:

/var/log/unison.log {
notifempty
daily
rotate 7
missingok
compress
}

5) Set up cron job(s). Create multiple profiles if specific paths need more frequent syncing. With silent=true, the jobs should produce no output (silent=true automatically sets batch=true).

Sample profile (/root/.unison/profile-name.prf)

# Reasonable defaults
auto=true
confirmbigdeletes=true
contactquietly=true
fastcheck=true
group=true
maxthreads=20
numericids=true
owner=true
times=true

# Dump an archive listing to ~/unison.dump
#dumparchives=true

# Skip confirmation
batch=true

# Suppress output (sets batch=true)
silent=true

# Run in a loop, repeating every X seconds (sort of daemon mode)
#repeat=60

# Log all sync operations
log=true
logfile=/var/log/unison.log

# Backup deleted files
backup=Name *
backuplocation=central
backupdir=/var/www/unison-backups


# Local root
root=/var/www/html/

# Remote root (the double forward-slash between IP and remote path is correct)
root=ssh://1.2.3.4//var/www/html/

# Resolve conflicts in favor of local root
prefer=/var/www/html/


# Limit to specific relative path (can specify multiple path= params)
#path=somepath/

# Don't sync (can specify multiple ignore lines)
ignore=Path */var/cache

03/08/09

Permalink 02:34:03 pm, by admin Email , 130 words   English (US)
Categories: Project Gallery

Change ZimbraMon Disk Thresholds

Edit the file at:

/opt/zimbra/libexec/zmdisklog

Look for these lines:

my $DISK_CRIT_THRESHOLD = 90;
my $DISK_WARN_THRESHOLD = 80;

Change them as desired to give different warning/critical levels.

In one case that we worked on, the server had multiple partitions. We wanted different thresholds on each partition which was accomplished with the following patch:

--- zmdisklog.orig 2009-03-08 15:10:26.000000000 -0400
+++ zmdisklog 2009-03-08 15:13:21.000000000 -0400
@@ -77,8 +77,12 @@
my (undef, $total, $used, $avail) = split(/\s+/, $df[0]);
my $pct=int(($used/$total)*100) if ($total > 0);
my $lvl = "info";
+if ($dev eq "/dev/sdb1") {
+ $lvl = "err" if ($pct > 95);
+} else {
$lvl = "err" if ($pct > $DISK_WARN_THRESHOLD);
$lvl = "crit" if ($pct > $DISK_CRIT_THRESHOLD);
+};
if ($lvl eq "info") {
Zimbra::Mon::Logger::Log( "$lvl", "$dt, DISK: ${hostname}: dev: $dev, mp: $mp, tot: $total, avail: $avail" );
} else {

03/06/09

Permalink 10:37:32 am, by admin Email , 37 words   English (US)
Categories: QMail

Disable Qmail Double Bounces

To cleanly handle double bounces:

1. Create a dot-qmail file at /var/qmail/mailnames/yourdomain.com/.qmail-doublebounce containing:

|exit 0

2. Route double bounces to this file:

echo yourdomain.com > /var/qmail/control/doublebouncehost
echo doublebounce > /var/qmail/control/doublebounceto

03/05/09

Permalink 12:27:09 pm, by admin Email , 52 words   English (US)
Categories: Email

Change outgoing IP address for SMTP

On a server, if outgoing email is being blocked by spam filters, I can sometimes get around the problem by using an IPTables rule to force the email out through a different IP address like this:

/sbin/iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source w.x.y.x

Permalink 07:17:23 am, by admin Email , 74 words   English (US)
Categories: General

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 function using find and sed:

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

03/02/09

Permalink 02:23:19 pm, by admin Email , 86 words   English (US)
Categories: Zimbra

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

Permalink 01:22:13 pm, by admin Email , 32 words   English (US)
Categories: Project Gallery

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;

Permalink 09:57:44 am, by admin Email , 148 words   English (US)
Categories: Project Gallery, Zimbra

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 =~ /(.+)\ 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]);

};

March 2009
Sun Mon Tue Wed Thu Fri Sat
 << < Current> >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Reliable Penguin offers Linux Server Migrations, Systems Administration & Programming. Visit our main website at:

http://www.reliablepenguin.com

Search

Bookmark and Share

XML Feeds

powered by b2evolution free blog software