Eventually /dev/null

Random thoughts from an emerging Programmer

DB2 Remote Connection

As I found out within the last days it isn’t that easy to find informations about how to connect Java through JDBC with a DB2 Database remotely. So if you should come into these troubles as well, take care of this:
As DB2 driver you need to use COM.ibm.db2.jdbc.net.DB2Driver which is located in the same file (db2java.zip) as the default driver (COM.ibm.db2.jdbc.app.DB2Driver) which is “promoted” on most sites. The problem with these two drivers is that they’re not able to work with the other kind of connection. So If you inserted the net driver you can’t create local connections and vice versa. If you want to be flexible you need to use as driver com.ibm.db2.jcc.DB2Driver which is capable to handle both types of connections. The driver can be found within the db2jcc.jar file, which should be located in the same place as db2java.zip. At least for me it was further needed to provide a license in order to establish a remote connection, to achieve this add a file called db2jcc_license_cu.jar or maybe some file which is similiar named to your Classpath.
Connection string: After some search I found the DB2 page where the remote connection string was described. The string has follow this scheme for remote connections: jdbc:db2://SERVERNAME:PORT/DATABASE.
Not sure if you can leave the DATABASE and run later a Connect to DATABASE Query. At least my quick tries resulted each time with an Exception caused by wrong connection strings.
If you don’t know on which port your DB2 Instance is running take a look at your /etc/services and look for the corresponding line.
Now you should be ready to successfully open a remote Connection.

Mongosniff: Error While Loading Shared Libraries: libpcap.so.0.9

Lately I’ve worked with mongoDB which is a great NoSQL database. A tool which can come in handy is mongosniff, which comes with mongodb binaries. Mongosniff is something like tcpdump for TCP/IP.
On my Fedora 16 x86_64 System I’m running mongodb binaries available from mongodb, this allows me to easily run the version I want. But mongosniff didn’t worked right out the box for it. When starting mongosniff I got following error: mongosniff: error while loading shared libraries: libpcap.so.0.9: cannot open shared object file: No such file or directory. So this mostly means that libpcap isn’t installed, but this wasn’t the case as you can see soon.
My first try was to install libpcap for my system but this didn’t solve the problem. A lookup with ldd showed that indeed libpcap.so.0.9 was missing for it:

1
2
3
4
5
6
7
8
9
$: ldd /usr/bin/mongosniff
       linux-vdso.so.1 =>  (0x00007fffa30d2000)
       libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003ef0400000)
       libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003655a00000)
       libpcap.so.0.9 => not found
       libm.so.6 => /lib64/libm.so.6 (0x0000003ef1000000)
       libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003654600000)
       libc.so.6 => /lib64/libc.so.6 (0x0000003ef0000000)
       /lib64/ld-linux-x86-64.so.2 (0x0000003eefc00000)

A check if any libpcap module was available showed that a too new version was installed and that a symlink as libpcap.so.0.9 was missing:

1
2
3
4
$: ls /usr/lib64/libpcap*
/usr/lib64/libpcapnav.so        /usr/lib64/libpcapnav.so.0
/usr/lib64/libpcap.so.1         /usr/lib64/libpcapnav.so.0.0.0
/usr/lib64/libpcap.so.1.1.1     /usr/lib64/libpcap.so

So creating a symlink for libpcap.so.0.9 solved the startup problem: ln -s /usr/lib64/libpcap.so.1.1.1 /usr/lib64/libpcap.so.0.9. If you’re running a 32bit mongodb version you may check your /usr/lib to see if the required libpcap is missing. Don’t know if this problem still exists if you’re running mongodb from the offical repositoy.

Crontab -r – a Logic Gap?

Just worked a bit with crontab to edit some no longer working cron job. But instead of typing crontab -e I had written crontab -r, without any warning or notice my crontab was dropped! What’s the logic behind that behaviour? Isn’t the normal, userfriendly way, that you have to confirm you want to drop something? All Programms I can remember want a confirmation for not saving data or dropping some file, or even for exiting.
I could life with the problem, if it wouldn’t be too likely to do the typo. But the keys are on a normal qwert(y|z) keyboard next to the other one, so a typo isn’t that unlikely. To avoid the problem I need to add the parameter -i to it, to be asked If I’m sure I want drop that crontab. Since when do I need to add additional parameter to have a higher security level? Normally you need to add parameters to avoid such behaviour not to initialize it.
But as I just see my crontab version is even the userfriendly one(on Debian 5 amd64), which offers such a parameter -i. The standard BSD(as on Debian 4 x86) one hasn’t this parameter nor does -r ask the user to confirm the operation.
Anyone knows why it behaves that way, I mean a multiliner crontab isn’t too nice to be lost by accident?

The Long and Stony Way to Get Mod_AuthMySQL Working

Somedays it’s really hard to come along with Linux, it’s apps and tools. Recently I’ve tried to use AuthMySQL for authentication within a certain webfolder. To reach this, many trails and even more errors were needed :(.
The first point was to configure the module correctly, which isn’t that easy, as no post tells which version of AuthMySQL is used nor that there are two of them out, additionally it seems that the module can handle at least partially both directives, but later more.
I’ve searched quickly for some resources about how to configure AuthMySQL, some of the commands worked other didn’t. After several tries with extensive watching the apache error.log I finally managed to get the authentication running, upto the point of the used Encryption. The first try was to use MD5, but sadly the module did not support that value, although somewhere was talked about it (later I encountered it was for the other module). No Problem there’s another MD5 Setting, let’s switch to that one (Crypt_MD5), now AuthMySQL was working, but didn’t accepted the login details. A google search later I discovered that Crypt_MD5 uses a default Salt of 12 signs (or so) to encrypt the passwords, but my password is encrypted with md5, so no way to get it working. After a few searches why md5 isn’t working with my version of the module I found that forum entry which revealed that there are two modules out, which offer Authentication through MySQL.
But as I already supposed Debian doesn’t offer a package for the other module or I didn’t find it, anyway I got to the website of the other module and downloaded it’s source code. A fast lookup on howto compile and install modules for apache showed that I need to run apxs. But for my debian install the application wasn’t installed, you need to get some apache-dev package to install apxs. A few minutes later I’ve got a matching package and installed it. Next problem: while compiling apxs throws an error 65536, but luckily I found soon an patch, in this blog entry a patch is supplied so that the module was successful compiled under my linux installation.
The needed renaming of the module directives was done quickly and finally I got the authentication through MySQL working.
Alltogether it took a few hours to get that simple job working, anyway I’ve increased my knowledge about Apache and Linux, which isn’t that bad :).
Maybe this post will help the one or other to solve his problems quicker, as it contains quite well condensed errors and their solution.
If you want to use AuthMySQL get this version as it supplies in my eyes the best functionality. The easiest way to differ both versions is that one requires underlines within the directives and the other one doesn’t (the one which is linked).

Internet Explorer and JavaScript Problems

I’ve seen in within my two years of JavaScript progamming some weird things, about browser behaviour. But the one I’ve discovered yesterday tops them all. Some of my JavaScript class use the document.createElement function within it’s init procedure. The Script is working fine used within one Website, even with IE. But when the Script is added to another Website, IE complaints that document.createElement isn’t supported by this Object. An alert directly before the call is executed shows:

1
2
3
function createElement() {
[native Code]
}

But it still doesn’t work in IE.
Someone ever encountered that problem? I’m currently missing a solutin except the try to manually create the HTML-Node.

Mbox to .eml Converter

If you need to extract all mails from a single mbox file to seperate .eml files, take a look at this tool. I had recently the need to do so, and this tool was just perfect for it. It lets you choose which files to extract from mbox to .eml. In order to import a normal GNU/Linux (any *nix?) mbox into the tool, you need to set as file-ending .mbx. The Only restriction is that it can only handle western character sets, but not sure if that’s a big problem, aren’t most Emails still in latin?
To run the tool you need to have installed Java Runtime 1.2 or higher

WordPress(/PHP) and the Byte Order Mask (BOM)

A few days ago I started to write since some time a Plugin for WordPress again, for a customer. As I read over on WordPress you shall declare the files as UTF-8, but I would have changed it myself as well. Now after some initial testings I encountered this Problem:
Warning: Cannot modify header information - headers already sent by (output started at /xampp/htdocs/blog/wp-content/plugins/phRelatedLinks.php:1) in /xampp/htdocs/blog/wp-includes/pluggable.php on line 776)

Ah yeah…some known Problem within the WordPress Universe and the PHP one as well, caused by the Problem that infront of the starting < ?php are some other signs. Now when WordPress wants to send the header Information of the Page the whitespace/sign was already sent, but the header needs to be the first part of the website which is sent…therefore PHP throws this error.
Unfortunally this wasn’t the case for my Problem. As I had no clue what it could be else I searched for some time, and anything I could find told it’s a problem with leading signs before < ?php. Luckily I found this Post with the same Problem, which solved it.
While saving my file with SciTE as UTF-8, SciTE added a Byte Order Mask to the file, which isn’t needed at all as UTF-8 doesn’t encounter differences between big-Endian and little-Endian. Anyway it’s now widely used to easily tell apart UTF-8 and ISO-8859. So if a file contains as starting Bytes: EF BB BF it’s (mostly) a UTF-8 formatted file. But as these Bytes aren’t displayed within SciTE at all, you can go crazy with it. To write a file without this optional BOM you need to select as Encoding UTF-8 Cookie within SciTE.
Now the real cause was found, and it wasn’t WordPress who tried to drive me crazy at all. A look within PHP revealed that PHP isn’t able to interpret these Bytes as mark for a following UTF-8 Encoding. The related Bug Post was closed as won’t fix for PHP 5/4, the correct behavior will be implemented with PHP 6+.
In the meantime I hope that not too many other people will encounter that Problem and if, they’re able to find the solution faster than me!

Image.onload() Problems

Since a while I’m working with Javascript. I have to say, that it’s for sure not that hard to write cross-browser Source Code, like it’s still with CSS. But some parts aren’t easy to get them working. A recent problem is indeed the image.onload. At first it’s obviously that you should register an onload EventListener, before you assign an Image, like this:

1
2
image.onload = function() { alert("let's do something in here!");};
image.src = "myURL";

As it’s quite possible that the other way around, the picture is already loaded before the EventListener is registered.
But Hey! That’s no reason to make this mistake a few times…Now after you solve that self-made problem you can run into the next one! Opera calls the onload Event, only if the Object is newly created or the Image loaded isn’t already cached. That’s the state of Opera 7.5, as I read several times on various sites, this problem was fixed with Opera 8.x. But now it seems that this Problem is back with Opera 9.26+( or earlier).
Unfortunately my Script needs to be noticed everytime a new Image is loaded, although it may already be cached. The only way I’m aware of getting what I want, is to disable the Cache of Opera, through Opera’s settings or per HTTP Header. Ok another way would be a function which looks the whole time if the image is changing, but both aren’t that what I’m searching for. Someone knows if it’s possible to get some real onload for Images in Opera, without any of the previously mentioned hack?
Or can Opera fix this problem? It’s working correctly in IE, why not in Opera?

Find: Missing Argument to `-exec`

That’s maybe some common Error you’re receiving, when you’re new to find and the exec parameter. So I encountered the Problem as well.
After a short research within the man page of find the problem was found: ; needs to be escaped with a Backslash \. The look over to my commandline just showed that this was already the case. Now the internet was asked and most results just reveal the same thing: escape the ; with a Backslash.
Some hits later I found a german page where they told that it’s even required that the \; is separated from the previous commands with a space \;. So it’s not enough to write:

wrong invocation
1
find <query> -exec <command>{}\;

, it needs to be (notice the extra whitespace between command and {}):

correct invocation
1
find <query> -exec <command> {} \;

Well from my point of view some mistake which can be fast overseen, even more if you suppose that {}\; should work out nicely as it’s something which occurs often or everytime within the exec(at least these groups of signs).

Restoring Windows

Just the latest example how stupid I can be sometimes:
I’ve dropped yesterday my Linux Partition from my laptop. It wouldn’t be that problematic if it hadn’t the Boot session on it. Anyway I didn’t noticed that big mistake until I restarted my Laptop and encounter some Error while Loading GRUB.
After the first seconds of thinking, what happened, I started to knock my head against the table(not really:)). As soon as I stopped to hate myself I made a search for a solution and quickly found an Answer: Start your PC with your Recovery CD and run fixmbr and fixboot. Ok, no big deal…as long as you have your Recovery CD with you, but I didn’t…(second time some knocking, was hearable).
So my next try was to get some Recovery Application on the base of some small DOS Boot, I found quickly something, anyway it didn’t worked for XP(at least for my PC it didn’t).
Next I’ve inserted the Vista Recovery from some friend( I would like to mention that without any Install you can run already some Safe-Mode like Vista…with working Notepad, aso.). I was even able to start a Cmd.exe, but the next shock wasn’t far as I noticed that fixmbr and fixboot didn’t worked within Vista. A new search was on the way, on how to get fixmbr&fixboot working on Vista Recovery CDs, again I had luck and found soon, a solution…you have to call them as Parameter through some other application:

1
2
bootrec.exe /fixmbr  
bootrec.exe /fixboot  

I’ve applied both commands, the had be done correctly and after a Restart I was able to Boot Windows again. The only good point is that I don’t have to take care on startup if the correct OS is selected, anymore :).
A side note for the next time I make any changes to an OS, be sure to have the recovery CD near myself!