Emailing cron output to different users

When a cron job generates output on either stdout or stderr, the output gets mailed to the owner of the crontab. Now, you can specify an alternative email address by setting the MAILTO environment variable in the crontab, but this applies to all jobs in the crontab.

So, if you want the output of different jobs to get mailed to different users, then you can just redirect the stdout and stderr of each job to the mail command like this:

13 02 * * *     /bin/backup 2>&1 | /usr/bin/mail -s "Cron <root@exobox> /bin/backup" \

MTR as a combined traceroute and ping tool

mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.” And it’s really cool.

Like ping, it sends “echo” packets from your machine to the target machine to measure latency and packet loss along the network path, but it continuously displays updated statistics in real time as it operates.

Like traceroute, it shows the names or IP addresses of each machine along the network path, also updating these statistics for each machine.

Here’s some (frozen) sample output from the ncurses mode (terminal mode) mtr:

                                My traceroute  [v0.71]
exobox (                                             Thu Dec 21 16:15:01 2006
Keys:  Help   Display mode   Restart statistics   Order of fields   quit
                                             Packets               Pings
 Host                                      Loss%   Snt   Last   Avg  Best  Wrst StDev
 1.                                         0.0%    20    0.4   0.3   0.2   0.7   0.1
 2.                                         0.0%    20    1.6   1.4   1.0   2.7   0.4
 3.                                         0.0%    19    1.3   1.3   1.0   2.7   0.4
 4.                               0.0%    19    1.1   1.2   1.0   2.7   0.4
 5.                           0.0%    19    1.4   2.6   1.2  16.0   3.3
 6.             0.0%    19    1.4   1.6   1.4   2.5   0.3
 7.                           0.0%    19  199.3  12.0   1.3 199.3  45.4
 8.                             0.0%    19    1.7  35.7   1.3 186.5  56.2
 9.                           0.0%    19    1.8   2.0   1.5   4.8   0.8
10.                            0.0%    19  284.6 292.2 278.3 305.8   8.7
11.        15.8%    19  286.2 291.9 278.6 325.2  11.5
12.        15.8%    19  313.2 323.8 311.3 340.5   8.6
13.          5.3%    19  319.6 331.1 314.1 404.6  20.3
14.         11.1%    19  696.0 718.7 693.3 797.2  33.7
15.         36.8%    19  347.4 354.9 342.5 368.7   8.6
16.        11.1%    19  421.5 423.6 411.1 438.2   7.8
17.        11.1%    19  433.9 438.9 422.4 514.1  22.0
18.                     33.3%    19  423.1 432.7 418.7 463.0  11.4
19.        27.8%    19  405.8 414.7 398.2 434.6  11.6
20.                         23.5%    18  404.8 418.1 399.9 485.8  21.9

Looking at the Avg column (units in ms), the above output shows that my network packets pass through Beijing Telecom’s routers to the U.S., then to the U.K., and finally to their destination in the Netherlands. A large latency increase occurs between lines 9 and 10 (presumably leaving P.R. China), and another between lines 13 and 16 (U.S. to U.K.).

mtr has some interesting display modes besides the above, where it shows the latency of each packet graphically according to a dynamic scale. In this way, the above points of really large latency can be easily detected.

mtr can be obtained from the mtr website, or it can be installed in Debian/Ubuntu by:

# apt-get install mtr-tiny


# apt-get install mtr

for the ncurses or X11 versions, respectively, although mtr-tiny appears to be installed by default in the Debian and Ubuntu machines I have tested. So you may already have it.

Ubuntu Open Week Begins Tonight

If you’re curious or interested in getting involved in the Ubuntu community, “Ubuntu Open Week” begins tonight. It’s “a week of IRC tutorials and sessions designed to encourage more and more people to join our diverse community”. More information is here:

The times in the calendar are UTC, so just add 8 hours for China. For example, the first session on Monday on the “Ubuntu Desktop Team – Sebastien Bacher” at 15:00 UTC will actually occur at 23:00 tonight, Beijing time. Of notable interest is the “Ask Mark” session on Tuesday, featuring Ubuntu founder Mark Shuttleworth.

By the way, I plan on attending some of the earlier-in-the-evening sessions, but once it gets too late I’ll just let my IRC client log the rest of them while I’m sleeping. 😉

How to send an entire domain to /dev/null in Postfix

At Exoweb, our software developers use bogus email addresses of the form * (where I mean “” literally, not as an example) to test their software’s ability to send email. Since I don’t want our Postfix server to attempt to deliver these messages out on the Internet, I need Postfix to handle these messages and blackhole them (make them disappear, sent to /dev/null). So what follows are instructions on how to blackhole an entire domain in Postfix.

First, we add a virtual_alias_maps entry to /etc/postfix/ so that we can specify as one of our virtual domains:

virtual_alias_maps = hash:/etc/postfix/virtual_alias

Inside /etc/postfix/virtual_alias, add a catchall address:      blackhole@localhost

We have to use blackhole@localhost here and not /dev/null/ because virtual_alias_maps cannot run commands—it can only forward to real addresses. So we put an entry inside /etc/aliases to handle the blackhole:

blackhole:      /dev/null

This assumes that one of your mydestination domains in is localhost so that Postfix will actually consult the aliases file.

In order to make these changes take affect, you have to rebuild the aliases database, build the virtual_alias database, and reload your Postfix configuration. Respectively:

# newaliases
# postmap /etc/postfix/virtual_alias
# postfix reload

Now, any emails you send to blackhole@localhost will disappear, and so will any emails addressed to (provided they are relayed through your Postfix server).

Footnote: The top-level and second-level domain names that are reserved for testing can be found in RFC 2606.

How to convert CHM files under Linux

CHM files, known as Microsoft Compressed HTML Help files, are a common format for eBooks and online documentation. They are basically a collection of HTML files stored in a compressed archive with the added benefit of an index.

Under Linux, you can view a CHM file with the xchm viewer. But sometimes that’s not enough. Suppose you want to edit, republish, or convert the CHM file into another format such as the Plucker eBook format for viewing on your Palm. To do so, you first need to extract the original HTML files from the CHM archive.

This can be done with the CHMLIB (CHM library) and its included helper application extract_chmLib.

In Debian or Ubuntu:

$ sudo apt-get install libchm-bin
$ extract_chmLib book.chm outdir

where book.chm is the path to your CHM file and outdir is a new directory that will be created to contain the HTML extracted from the CHM file.

In other Linuxes, you can install it from source. First download the libchm source archive from the above website. I couldn’t get the extract_chmLib utility to compile under the latest version 0.38, so I used version 0.35 instead.

$ tar xzf chmlib-0.35.tgz
$ cd chmlib-0.35/
$ ./configure
$ make
$ make install
$ make examples

After doing the “make examples“, you will have an executable extract_chmLib in your current directory. Here is an example of running the command with no arguments and the output it produces:

$ ./extract_chmLib
usage: ./extract_chmLib <chmfile> <outdir>

After running the utility to extract the HTML files from your CHM file, the extracted files will appear in <outdir>. There won’t be an “index.html” file, unfortunately. So you’ll have to inspect the filenames and/or their contents to find the appropriate main page or Table of Contents.

Now the HTML is yours to enjoy!


I got help in writing this article from here and here.

Spaghetti Wiring

When you work in a software development shop, spaghetti code is most certainly frowned upon. What about spaghetti wiring?

[Spaghetti wiring]

So this was the remains of the small electrical fire that occurred 15 minutes before I arrived at the office today… the charged main circuit to the room that houses most of our developers, their computers, and the all-important Ice Box.

Do you think this is enough to convince the building management that the building’s wiring needs professional help? No, unfortunately, I think we’ll still have to fight them to get adequate electrical capacity and safety. 🙁