Just another WordPress site

To dump the content of a postfix .db file just type:

# you have to ommit the file's .db extension:
postmap -s virtual_aliases

Today, the following question came up: How many times do i have to roll the dice to get every number at least once.
I calculated, that the expected value shoud be 6*(1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6) = 14,7 and that i would need 6^2 = 36 throws to be 99% sure.
Well, but i wasn’t really sure about it. That’s why, i thought, that i should write a little php script for that:

if(!is_numeric($_SERVER['argv'][1])) die("Zahl eingeben!\n");
for($i=6; $i<=36; $i++) $fails[$i]=0;
// $fails=array(15=>0, 25=>0, 36=>0);
for($i=0; $i<$_SERVER['argv'][1]; $i++) {
        $array=array(false, false, false, false, false, false);
        while($ii<100000) {
                foreach($array as $val) {
                        if($val===false) {
                if($leave) break;
        for($num=6; $num<=36; $num++) {
                if($ii>$num) $fails[$num]++;
echo "Erfolgschnitt : ".($erfolg/$_SERVER['argv'][1])."\n";
foreach($fails as $num=>$val) {
        echo "Failquote $num: ".(($fails[$num]/$_SERVER['argv'][1])*100)."%\n";

I realized, that it took a lot of time and i wanted to have some results today! ;-) After approximately 20 seconds i stopped the script. I think, php’s internal datastructure isn’t that optimal.
So i thought, let’s write a c version to get the results, that i wanted to have:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#define bool int
#define true 1
#define false 0
int main (int nArgs_p, char *pszArg_p[])
  long      lSize = 0;
  int       i=0;
  int       ii=0;
  int       iii=0;
  bool      leave=true;
  bool      wuerfl[6];
  int       fails[37];
  long long erfolg=0;
  long long llSum;
  srand ( time(NULL) );
  for(i=0; i<37; i++) fails[i]=0;
  if (nArgs_p > 1)
    lSize = atol(pszArg_p[1]);
  else {
    printf("Zahl eingeben!\n");
    return 1;
  for(i=0; i<lSize; i++) {
    for(ii=0; ii<6; ii++) wuerfl[ii]=false;
    while(ii<100000) {
      for(iii=0; iii<6; iii++) {
        if(wuerfl[iii]==false) {
      if(leave) break;
    for(iii=6; iii<=36; iii++) {
      if(ii>iii) fails[iii]++;
  printf("\nErfolgsschnitt bei %ld:  %14.9lf", lSize, ((double)erfolg / (double)lSize));
  for(i=6; i<=36; i++) {
     printf("\nFailquote %2ld: %14.6lf%%", i, ((double)fails[i] / (double)lSize)*100);
  return 0;

After that, i was a bit curious about hiphop’s performance on this. According to facebook they compile your php source to c++ source.
At the end i’ve run each version in the following order: C, hiphop(hphp) and php.
…and the results are:

  1. approx. 1s in C
  2. approx. 9.5s in hphp (so the c version is 9.5 times faster)
  3. approx. 34.3s in php (so the hphp version is 3.6 times faster)

Amazing! I think hiphop uses another datastructure to store the values. :)

mweber@ubuntu:~# time ./wuerfeln 1000000
Erfolgsschnitt bei 1000000:    14.704265000
Failquote  6:      98.441900%
Failquote  7:      94.586800%
Failquote  8:      88.612600%
Failquote  9:      81.068600%
Failquote 10:      72.816500%
Failquote 11:      64.368000%
Failquote 12:      56.239300%
Failquote 13:      48.642500%
Failquote 14:      41.773900%
Failquote 15:      35.687500%
Failquote 16:      30.299300%
Failquote 17:      25.612700%
Failquote 18:      21.578400%
Failquote 19:      18.172300%
Failquote 20:      15.255100%
Failquote 21:      12.770600%
Failquote 22:      10.671400%
Failquote 23:       8.923200%
Failquote 24:       7.464500%
Failquote 25:       6.230700%
Failquote 26:       5.212600%
Failquote 27:       4.352800%
Failquote 28:       3.634500%
Failquote 29:       3.025400%
Failquote 30:       2.513500%
Failquote 31:       2.092600%
Failquote 32:       1.738300%
Failquote 33:       1.449800%
Failquote 34:       1.200900%
Failquote 35:       1.002800%
Failquote 36:       0.833600%

real    0m0.965s
user    0m0.964s
sys     0m0.000s

mweber@ubuntu:~# time ./wuerfelnhphp/program 1000000
Erfolgschnitt : 14.709768
Failquote 6: 98.4506%
Failquote 7: 94.5824%
Failquote 8: 88.5587%
Failquote 9: 81.0715%
Failquote 10: 72.8546%
Failquote 11: 64.4157%
Failquote 12: 56.2674%
Failquote 13: 48.6804%
Failquote 14: 41.7905%
Failquote 15: 35.6534%
Failquote 16: 30.2511%
Failquote 17: 25.5854%
Failquote 18: 21.5718%
Failquote 19: 18.1589%
Failquote 20: 15.276%
Failquote 21: 12.7943%
Failquote 22: 10.7217%
Failquote 23: 8.9401%
Failquote 24: 7.4972%
Failquote 25: 6.2734%
Failquote 26: 5.2445%
Failquote 27: 4.3744%
Failquote 28: 3.6513%
Failquote 29: 3.0443%
Failquote 30: 2.5386%
Failquote 31: 2.1068%
Failquote 32: 1.761%
Failquote 33: 1.4654%
Failquote 34: 1.2189%
Failquote 35: 1.0189%
Failquote 36: 0.8557%

real    0m9.449s
user    0m9.437s
sys     0m0.012s

mweber@ubuntu:~# time php ./wuerfeln.php 1000000

Erfolgschnitt : 14.694884
Failquote 6: 98.4516%
Failquote 7: 94.5731%
Failquote 8: 88.5453%
Failquote 9: 81.0262%
Failquote 10: 72.7975%
Failquote 11: 64.3744%
Failquote 12: 56.1996%
Failquote 13: 48.5864%
Failquote 14: 41.6888%
Failquote 15: 35.5515%
Failquote 16: 30.157%
Failquote 17: 25.4991%
Failquote 18: 21.492%
Failquote 19: 18.0759%
Failquote 20: 15.1766%
Failquote 21: 12.7463%
Failquote 22: 10.6968%
Failquote 23: 8.9528%
Failquote 24: 7.4691%
Failquote 25: 6.2347%
Failquote 26: 5.2058%
Failquote 27: 4.3439%
Failquote 28: 3.6347%
Failquote 29: 3.0244%
Failquote 30: 2.5226%
Failquote 31: 2.0964%
Failquote 32: 1.7409%
Failquote 33: 1.447%
Failquote 34: 1.2037%
Failquote 35: 1.0115%
Failquote 36: 0.842%

real    0m34.257s
user    0m34.218s
sys     0m0.032s

sudo !!

sudo !! executes your last command as root:

marco@ubuntu:~$ iptables -L
iptables v1.4.4: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
marco@ubuntu:~$ sudo !!
sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

When it comes to throttling the download speed a lot of people use mod_throttle. But in case you want to limit on a per download basis and you’re already using PHP to serve them, there is a simple way to limit the bandwidth:

header('Content-type: application/x-gtar');
header('Content-Disposition: attachment; filename="download-archive.tgz"');
$kb_s=40; // set limit to 40 KB/s
if($kb_s<0) $kb_s=0;
$fp=fopen('download-archive.tar.gz', 'r');
while(!feof($fp)) {
        echo fread($fp, 1024);

Some months ago i’ve discovered Crashplan and i couldn’t believe my eyes. They say, that you have unlimited backup storage for just 3$ per Month!

So i though, let’s give Crashplan a try. A one year license for 49,99$ isn’t that much money you risk. The data, that i wanted to backup has a size of 3.1TB and the computer has a 100MBit connection to the Internet.

Finally, i started the backup: And how long does it take? Just 2.8 years! Well, i think, it’s not a big surprise at all. If they were not lying about the unlimited disk space, they would have to limit the bandwidth to make it a profitable service.

If you want to use crashplan to backup just some small files to the “cloud”, it can be a good product. But if you try to use it as a real backup solution for your disks, you should better use another computer, since the backup takes about 1 year per TB, which is about 1 Week per 20GB.

So does Crashplan really offer unlimited storage? In theory yes, but in practice i have to say no.

Beim Ubuntu Bildschirmschoner gibt es die Möglichkeit eine Nachricht zu hinterlassen.

Leider kann dieses Feature auch von Kollegen dazu missbraucht werden, 1000ende Nachrichten zu hinterlassen.

Deswegen hier ein Tutorial, wie man es abschalten kann:

  • vi /usr/share/gnome-screensaver/lock-dialog-default.ui
  • nach auth-note-button suchen
  • Dann das visible property auf False √§ndern.

In case you have skype installed on a server, an idling Skype can suddenly consume more bandwidth, than you want. (I think, that is has become a supernode.)
Well whatever skype needs to do, here is a simple solution on how to limit the bandwidth for your skype user (in my case userid 1007):

# marking all tcp/udp packages of the skype user
iptables -t mangle -A OUTPUT -p tcp -m owner --uid-owner 1007 -j MARK --set-mark 12
iptables -t mangle -A POSTROUTING -p tcp -m owner --uid-owner 1007 -j MARK --set-mark 12
iptables -t mangle -A OUTPUT -p udp -m owner --uid-owner 1007 -j MARK --set-mark 12
iptables -t mangle -A POSTROUTING -p udp -m owner --uid-owner 1007 -j MARK --set-mark 12
# setting the bandwith
tc qdisc del dev eth0 root
tc qdisc add dev eth0 root handle 2 htb default 1
tc filter add dev eth0 parent 2: protocol ip pref 2 handle 12 fw classid 2:6
tc class add dev eth0 parent 2: classid 2:6 htb rate 5Kbit ceil 250Kbit

That’s it. You can experiment with the rate, ceil, cburst, burst settings…

From time to time you might need these commands. This is just a post, to have them ready. I don’t want to read the man again. :)

How to connect with a small bandwith?

ssh -C user@host # gzip compression, very useful for surfing over GPRS

How to limit a ssh copy in Kbit/s ?

scp -l 10000 file user@host:path/ # just upload with 10Mbit/s

How to set up a dynamic socks proxy (i.e. for surfing with firefox) ?

ssh -f -N -D23456 user@host # you can now surf with firefox, when using: as socks proxy

How to set up a static port forwarding (i.e. for local port forwarding)?

ssh -f -N -L localip:localport:remotehost:remoteport user@host # forward remotehost:remoteport ---> localip:localport


In case you have a host, that frequently sends out commands to another host, you might be interested in speeding up, the time it takes to inkove the command on the remote host. For lightweight commands, it usually takes more time to set up the ssh tunnel, than it takes to execute the command.
That’s where ssh connection multiplexing can have a huge impact on the overall performance.

Setting up the multiplexing connection with a ssh_config file

First we need to setup the multiplexing on our local machine. For that we need to add some lines to the ~/.ssh/config file:

Host remote.host.tld
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p

In case you’ve just created the file, ensure that you set the permissions to 600 ( chmod 600 ~/.ssh/config ).

Now you can start the master connection:
ssh user@remote.host.tld
As long as the master connection is running, you can simply create slave connections by typing:
ssh user@remote.host.tld

Setting up the multiplexing connection by hand

Set up the master connection:
ssh -M -S ~/master.sock user@remote.host.tld
Start slave connections:
ssh -S ~/master.sock user@remote.host.tld
You might consider adding the -i option to the ssh commands.


At Jamendo we use Skype a lot. Therefore i thought, that it would be nice to get Skype instant messages from the Zabbix Server. My requirements were:

  1. must run on Ubuntu Server
  2. no X.org, KDE or Gnome – it must be a light solution!
  3. just install packages with apt (except for skype) – don’t want to update some software by hand.
  4. init.d script, that starts the “skype notification service”

Installing the skype notification software

Installing the basic components:

# installing the user, that runs the service
useradd skype
# installing the x server
apt-get install xvfb
apt-get install fluxbox x11vnc
# installing skype requirements
apt-get install dbus
apt-get install libasound2 libqt4-dbus libqt4-network libqtcore4 libqtgui4 libxss1 libpython2.6 libqt4-xml libaudio2 libmng1 fontconfig liblcms1
apt-get install lib32stdc++6 lib32asound2 ia32-libs libc6-i386 lib32gcc1
# wget http://www.skype.com/go/getskype-linux-beta-ubuntu-32 -O skype-linux-beta.deb
wget http://www.skype.com/go/getskype-linux-beta-ubuntu-64 -O skype-linux-beta.deb
# if there are other unresolved dependencies install missing packages using apt-get install and then install the skype deb package again
dpkg -i skype-linux-beta.deb
# installing Skype4py
wget 'http://sourceforge.net/projects/skype4py/files/skype4py/'
tar -xzf Skype4Py-
cd Skype4Py-
python setup.py install

Now we have all the things we need.
The next step we perform as skype user!
Just unpack these skypescripts.tar into the skype home directory.

Setting up the skype notification service

Please ensure, that you have vncviewer installed on your (local) ubuntu workstation.

  1. Log in to your server: ssh -L 5900: ‘skype@your.zabbix.server’
  2. start xfvb, fluxbox and skype: ./start-server.sh start
  3. start the vnc server: ./start-vnc.sh start
  4. on your local ubuntu workstation you start vnc-viewer: vncviewer
  5. You should now be seeing the fluxbox desktop and skype
  6. Enter the username and password and ensure, that the credentials get saved.
  7. Go to settings and set the following options
    1. no chat history
    2. just people on my list can write me
    3. just people on my list can call me
  8. Send your first skype message on the server as skype user: ./sendim.sh ‘USERNAME’ ‘HELLO WORLD’
  9. Skype asks now, if skype4py should be allowed. Click on remember and allow!
  10. stop the vnc-server: ./start-vnc.sh stop

Now the skype service is up and running.

Configuring the zabbix server

That’s the easy part.

  1. Just check in your zabbix_server.conf to where the AlertScriptsPath points to.
  2. Then add a symbolic link of sendim.sh in this directory. ( Zabbix calls the script like this: scriptname username subject message )
  3. Go to the zabbix frontend and create the new Skype media type:
    • Description: Skype
    • Type: Script
    • Script name: sendim.sh
  4. Finally, set up your skype address in your profile and check if you have an action, that sends messages to your all medias or skype media.

And that’s it, you should now receive messages from Zabbix. Just test by crashing your infrastructure… ;)