Interactive JavaScript console

I found an interesting tutorial which explains how to set up an interactive JavaScript console using Rhino.

Jivedude pointed out that there's a problem with it: putting jar files in lib/ext is a bad idea, since every single Java app will then embed these libraries, even if they don't need them.
In addition to the obvious bloat problem, this can also cause version and incompatibility issues. His suggestion: use java -cp (classpath).

Assuming I put the jar files in /home/erik/lib/, the command then becomes:
java -cp '/home/erik/lib/*' org.mozilla.javascript.tools.shell.Main"

Lightning intro: Fabric

Fabric is a nifty Python tool to automate deployment and system tasks. You define the commands you want to be able to use in fabfiles: a file called fabfile.py, or a directory (with __init__.py) called fabfile, either under the current working directory or X levels higher. This lets you define different fabfiles for different projects.

One thing I'm planning to use it for is quickly adding my RSA key to development servers. With a fabfile that looks like:

from fabric.api import run, put

def prepare_ssh()
    run('if [ ! -e /root/.ssh ]; then mkdir /root/.ssh; fi')
    put(local_path='/home/erik/.ssh/id_rsa_dev.pub', \
                   remote_path='/root/.ssh/id_rsa_dev.pub')
    run('cat /root/.ssh/id_rsa_dev.pub >> /root/.ssh/authorized_keys')


and a .fabricrc in my home directory that looks like:

user = root
key_filename = /home/erik/.ssh/id_rsa_dev


I can use this as:

fab -H [ipaddress1],[ipaddres2],[ipaddress3] prepare_ssh


This will copy my RSA key to the remote hosts, enabling me to login as root without a password. Should I define other commands, Fabric won't even ask me for a password anymore: thanks to the .fabricrc file it will try to log in as root with the specified ssh key.

Creating a new report in OpenERP with the OpenOffice.org report designer

Creating a new OpenERP report with the OpenOffice.org (OOo) report designer isn't very hard, provided you know the right steps to get started. I'm assuming you have the base_report_designer module installed in your OpenERP setup.


  1. In OOo, open a new document.
  2. Connect to your OpenERP server:

    1. OpenERP Report Designer -> Server Parameters
    2. Use the 'Change' button to enter the Server URL parameters
    3. Enter your database, login and password
    4. Click Connect

  3. In the OpenERP Report Designer menu, choose "Open a new report"
  4. You'll be given a list of objects to choose from - choose the one you want your report to be about
  5. Add a loop (either via the menu or via the toolbar, which can be enabled via View -> Toolbars -> Add-On 1). If all is well, you'll have a single object to choose from. This loop needs to be in your document to ensure that you can add the sub-fields of your chosen object to the report.
  6. You can now add fields, layout, everything you like to your report. Don't forget to save your work every now and then. Use the "Send to the server" option in the OpenERP Report Designer menu to upload your report to your OpenERP server. It will be available immediately.


This procedure was tested on OpenERP v.6.0.2

Conky with Awesome3

I've managed to get Conky configured as a bar at the bottom of my screen in Awesome3, while keeping windows from overlapping with it. In Awesome2 it was possible to pipe Conky's output into awesome-wm, in Awesome3 this isn't the case any more.

The solution is to create a very horizontal Conky configuration and combine that with a one-pixel-wide wibox at the place where you place your Conky bar. The wibox will prevent windows from hiding your conky, and with the right colour configurations it will look like part of your AwesomeWM.

The Awesome configuration ( ~/.config/awesome/rc.lua ) looks like this:

mystatusbar = awful.wibox({ position = "bottom", screen = 1, ontop = false, width = 1, height = 16 })


  • position = "bottom" puts the wibox at the bottom of the screen
  • screen = 1 places the wibox on screen 1
  • ontop = false means it doesn't have to be on top of other windows (it'll be empty anyway)
  • width = 1: one pixel wide is enough
  • height = 16: in my case, this is exactly the height of my Conky, so windows will touch it without overlapping


And the Conky configuration( ~/.conkyrc ).

In the TEXT block, notice the \ at the end of every line - this is equivalent to putting the whole thing on one line, only it's easier to read and maintain. There should be no blank lines after the last configuration line, because Conky will draw them.

Of course, if you want {n} lines, you can. Just make sure to adjust the height of your wibox accordingly.

alignment bottom_middle
background yes
border_width 1
cpu_avg_samples 2
default_color 222222
default_outline_color 222222
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
use_xft yes
#xftfont DejaVu Sans Mono:size=12
xftfont Sans Mono:size=8
gap_x 5
gap_y 0
minimum_size 1260 6
maximum_width 1260
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no
own_window no
own_window_class Conky
own_window_type desktop
own_window_transparent yes
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer left
show_graph_scale no
show_graph_range no
format_human_readable yes

color1 666666
color2 888888
color3 444444

mpd_host 127.0.0.1

TEXT
${if_mpd_playing} [${mpd_status} - ${mpd_elapsed}/${mpd_length}] ${scroll 35 5 ${mpd_smart}} ${else} \
${color1}Activity on /dev/sda:${color} ${diskiograph 10,50 000000 ff0000 -t}${endif} \
${alignr}${color1}br0 [${color3}${addr br0}${color}]: ${color1}Up:${color} ${upspeed br0} ${color1} - Down:${color} ${downspeed br0} \
${alignr}${color1}Battery: [${color3}${acpiacadapter}${color1}] ${color}${battery_percent BAT1}% ${battery_bar 5,50 BAT1} | \
${color1}CPU: ${color} ${cpu}% ${cpubar cpu0 5,50} ${color2}CPU1: ${cpubar cpu1 5,50} CPU2: ${cpubar cpu2 5,50} ${color}| \
${color1}RAM:${color} ${memperc}% ${membar 5,50}

SNMP trap forwarding to multiple destinations

It's quite simple, really... I'm not sure why it didn't work sooner. All that's needed in /etc/snmp/snmptrapd.conf is this:

disableAuthorization yes

forward default :162
forward default :2162


Ubuntu frustrations

I'm installing an Ubuntu 10.04 server at work. Because of proxy and internet configurations I'm installing packages from the CD instead of using the online repo's. No problem, I've done this before on virtual test machines without internet connectivity, it worked flawlessly.

Only those machines were 8.04. Not 10.04.

First problem: apt-cdrom add. For some reason it insists that the cd-rom can be found on /dev/sr1. Why it ignores /dev/sr0, which is where the cd-rom actually lives, is beyond me. The solution to this one is to configure a mountpoint in /etc/fstab (to /mnt/cdrom or so), and use

apt-cdrom -d /mnt/cdrom add

If you're lucky, apt will mount the cd-rom in /media/apt. If not, try a few more times until it works. If it's going to ignore the mountpoint anyway, shouldn't I be able to just tell apt-cdrom what device to use instead of what mountpoint?

Of course, after commenting out the online repos in /etc/apt/sources.list and running apt-get update, installing packages still doesn't work. No sirree, that would be too easy.

Failed to fetch cdrom:[Ubuntu-Server 10.04.2 LTS _Lucid Lynx_ - Release amd64(20110211.1)]/pool/main/p/patchutils/patchutils_0.3.1-2build1_amd64.deb File not found

And so on and so forth... not a single file can be cound, even though they do exist under /media/apt/pool/main/blablablablabla. You know, the point where apt actually mounted the cd-rom while ignoring my mountpoint?

The solution turns out to be really simple:

ln -s /media/apt /cdrom

Yes, you need a /cdrom directory or symlink in which the files on the cd-rom can be found, because the configured mountpoint in /etc/fstab and the one apt chose all by itself aren't enough.

User-friendly distro my ass...

pear behind a proxy server

So it turns out that pear (PHP Extention and Application Repository - http://pear.php.net ) completely ignores the $http_proxy environment variable:
hostname:~ # pear install HTML_Template_IT
No releases available for package "pear.php.net/HTML_Template_IT"
Cannot initialize 'channel://pear.php.net/HTML_Template_IT', invalid or missing package file
Package "channel://pear.php.net/HTML_Template_IT" is not valid
install failed


Pear has its own configuration, complete with proxy server setting:

hostname:~ # pear config-show
Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels auto_discover
Default Channel default_channel pear.php.net
HTTP Proxy Server Address http_proxy


So once that is updated with the system proxy server, everything works just fine:
hostname:~ # pear config-set http_proxy $http_proxy
config-set succeeded
hostname:~ # pear install HTML_Template_IT
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading HTML_Template_IT-1.3.0.tgz ...
Starting to download HTML_Template_IT-1.3.0.tgz (23,309 bytes)
........done: 23,309 bytes
install ok: channel://pear.php.net/HTML_Template_IT-1.3.0


Grub not loading after upgrade from Vista to Windows 7

On my work laptop, I dual-boot Windows Vista Enterprise (in case it's necessary at a customer site) and Gentoo (if I get to do things my way ;-) ). I recently decided to upgrade Vista to Windows 7, which worked just fine (after installing a meeljon updates - it had been a while).

As expected, Windows 7 obliterated my MBR. Bye-bye GRUB, Gentoo LiveCD to the rescue!

In the livecd I mounted my / (on /dev/sda3), /proc and /dev to /mnt/gentoo and chrooted in:

# mount /dev/sda3 /mnt/gentoo

# mount -t proc none /mnt/gentoo/proc

# mount -o bind /dev /mnt/gentoo/dev

# chroot /mnt/gentoo /bin/bash

Now run grub, let it re-write itself to the MBR and everything's happyhappy-joyjoy again, right?

# grub

grub> root (hd0,2)

grub> setup (hd0)

grub> quit

# reboot

Right after POST, I get greeted by a blinking cursor, and that's it. No GRUB, no message, nothing. Just that blinking cursor, mocking me. Back to the livecd, and chrooting into my gentoo installation once again. I used to use grub-install, so I decided to try that again (important: after chrooting - it's not necessary but the command is different!)

# grub-install /dev/sda

/dev/sda does not have any corresponding BIOS drive

Apparently GRUB doesn't have a proper device map. Time to refresh it:

# grub-install --recheck /dev/sda

/dev/root: not found or not a block device

This one is new ... df -h reveals that / is mounted as /dev/root, instead of the expected /dev/sda3 and that /dev/root does not exist (of course - that bind command I used right before chrooting? /dev/root didn't exist in the livecd environment). A symlink ought to fix this:

# ln -s /dev/sda3 /dev/root

# grub-install /dev/sda

One reboot later my grub is back where it's always been, offering me the choice between Gentoo and Windows 7.

Shutting down Windows from Linux

I had to do some research on how to remotely shut down a Windows computer from a Linux host and decided to share :-)

My test environment:


  • Gentoo linux running on my laptop
  • Windows XP SP3 running in a VirtualBox guest


The command (you need Samba installed on your Linux machine):

net rpc shutdown -t 10 -f -C "Remote shutdown initiated" -I 192.168.56.2 -U Erik

Broken down, that becomes:


  • -t 10 to give users 10 seconds to hit Ctrl-S
  • -f to force applications to quit without asking the user to save (so they can't get in the way of the shutdown)
  • -C "Remote shutdown initiated" is the message that should be displayed to any logged-in users
  • -I 192.168.56.2 the IP address at which the machine to shut down is located. In my case, the host-only network adapter
  • -U Erik is my username on the Windows machine. Works also as \ (don't forget to escape the backslash if your shell requires it!) or as \
  • If you like, you can add -r to reboot the machine instead of shutting it down.


If you don't want to be asked for your password, append it to your username with a % sign, like so: -U %

Of course, with Windows being involved, this doesn't work right out of the box ;-) In my case, after being asked for the password the net rpc command reported "Shutdown of remote machine succeeded". The Windows XP machine didn't shut down. It didn't even show me a message. A little Wireshark magic ended up revealing the error code "WERR_ACCESS_DENIED" being sent across the wire. (note to self: maybe a newer version of samba will actually do something with this error?)

Long story short: the solution is to have file sharing enabled, but to disable simple file sharing. To do so, open Explorer, go to Tools -> Folder options -> View (yes, it's the most logical place to put this ) and uncheck "Use simple file sharing" (all the way at the bottom of the list).

Error: Could not stat() command file '/var/lib/nagios3/rw/nagios.cmd'!

I ran into this error while messing around with nagios. Manually playing around with on /var/lib/nagios3/rw/nagios.cmd and its containing directories didn't seem to help much, so I went a-googlin'.

Here is the solution.

In short: (in case that blog goes down and I need it again ;-) ) :

sudo /etc/init.d/nagios3 stop
sudo dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
sudo dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
sudo /etc/init.d/nagios3 start