Howto connect OpenOffice to MS SQL server

Just had to connect to a MS SQL server that holds collected SAR statistics from our production servers.

Until now I used Toad in a virtual XP machine, but there has to be some way to connect in a graphical way from Linux too. And indeed there is!

Tools needed:

I chose JTDS, got the JAR file and copied it somehwere in the classpath. On OpenSUSE that is /usr/share/java. You can also add it in OpenOffice directly: Extras -> Options -> Java -> Classpath

Then fire up OpenOffice Base, and in the database wizard

  1. Open existing Database
  2. JDBC
jdbc:jtds:sqlserver://hostname:portnumber/databasename

The port number usually is 1433. The JDBC driver class is

net.sourceforge.jtds.jdbc.Driver

Then enter the db username, in the next step enter the password, and connect.

That’s it.

 

Howto use KDE4’s device notifier to play a DVD in SMplayer

Just finally figured this one out! It’s possible to add an entry to KDE4’s device notifier, so you can just click & play a DVD in SMplayer. Awesome!

You need a very recent SMplayer and Mplayer, latter one compiled with dvdnav support.

  1. In SMplayer’s preferences, go to mouse & keyboard -> mouse, and for left click select "Activate option in DVD menus".
  2. Create a file called smplayer-playdvd-predicate.desktop
    in $KDEDIR/share/apps/solid/actions, here that means /usr/kde/svn/share/apps/solid/actions/smplayer-playdvd-predicate.desktop, with following in it:
[Desktop Entry]
X-KDE-Solid-Predicate=[ StorageVolume.ignored == false AND OpticalDisc.availableContent == 'Data|VideoDvd' ]
Type=Service
Actions=open;

[Desktop Action open]
Name=Play DVD with SMplayer
Exec=smplayer dvdnav:////%d
Icon=smplayer

Now restart KDE, insert a DVD in your drive, or load DVD ISO image in cdemu, wait for the device notifier to pop up, and select.

Device notifier play DVD in SMplayer

That’s it!

Overlay with Qt 4.5 snapshot ebuilds

Recently stumbled over this blog post: http://labs.trolltech.com/blogs/2008/12/04/how-kde-4-is-blocking-qt-45/

Looks like it’s usable for KDE 4 trunk already, and the improvements to the WebKit engine got me interested in trying it. So I spend 2 hours in creating ebuilds for the Qt 4.5 snapshots – based on the split Qt 4.4.2 ebuilds in portage.

That actually wasn’t that hard to do, just fixing the qt4-build.eclass to include that 4.5.0_pre* version, and adding one line to qt-core ebuilds (adding src/tools/bootstrap to the targets). Other than that, it compiled fine. Easy.

The overlay can be found in my SVN:

svn co http://gimpel.ath.cx/svn/qt-snapshots

There is an update-qt-ebuilds.sh script in the Scripts/ subfolder, which should generate an updated headers tarball and update all ebuilds. Just adjust that distdir variable.

And now the usual warnings etc: USING THE EBUILDS IN THIS OVERLAY MIGHT KILL YOUR CAT, BURN YOUR HOUSE, BREAK YOUR CAR AND YOUR KDE4 and whatnot else. Use at your own risk!

Enjoy.

BASH arrays and filenames with spaces

I’m sure I can use this one quite often.

1) Arrays are nice to avaoid temporaray files

2) Spaces in file names are a PITA. But there are nice ways to work around this

Array[0]="/some/path/to/mooo foo.txt"
Array[1]="/some/path/to/mooo foo bar 2.txt"
Array[2]="/some/path/to/mooo foo bar 3.txt"

There we have some example array.

for ((i=0;i<${#Array[@]};i++)); do echo ${Array[$i]}; done
/some/path/to/mooo foo.txt
/some/path/to/mooo foo bar 2.txt
/some/path/to/mooo foo bar 3.txt

Ok, now what if want to pass that to ls, we could quote it somehow. Or use some pattern expansion to replace the space with backslash space, like

for ((i=0;i<${#Array[@]};i++)); do echo ${Array[$i]// /\\ }; done
/some/path/to/mooo\ foo.txt
/some/path/to/mooo\ foo\ bar\ 2.txt
/some/path/to/mooo\ foo\ bar\ 3.txt

Great! Another way would be to temporarily change the special variable $IFS that determines which character is used for word splitting. Let’s set this to “newline”

OLDIFS="$IFS"
IFS=$'\n'

for ((i=0;i<${#Array[$i]};i+=1)); do
   ls ${Array[$i]}
done

IFS="$OLDIFS"

That $IFS change can also be used in all sorts of other loops. Hell, I’m going to need that really often. Thanks to the guys on http://forums.gentoo.org/viewtopic-t-714971.html

Howto: Log firewall from OpenWrt to a remote rsyslog

This is how I got remote logging from my OpenWrt router to the syslog daemon on the server box.

On the server side, I enabled remote logging over UDP (refer to the rsyslog or syslog-ng documentation).

On the OpenWRT box following steps are needed

Enable remote syslog logging

Edit /etc/config/system and enable remote logging by adding:

option 'log_ip' '192.168.1.2'

Now reboot the router and see if it logs correctly.

Enable firewall logging (-j LOG)

Update (2013): In recent Openwrt builds this is as simple as editing /etc/config/firewall and adding a line to each zone that you want to get logged

config 'zone'
        option 'name' 'wan'
        ...
        option 'log' '1'

That’s all.

 

The info below is valid only for old OpenWRT builds Kamikaze 8.09 and older!

Then I had to get IPtables to produce some log output. With Kamikaze’s new firewall config layout this was a bit tricky. I decided to just log SYN flood protection actions, and the dropping of INVALID packets on INPUT and FORWARD chains. Therefore we need to edit /lib/firewall/uci_firewall.sh and add 3 lines (those with -j LOG)

In function fw_defaults()

$IPTABLES -A INPUT -m state --state INVALID -j LOG --log-prefix "DROP INVALID (INPUT): "
$IPTABLES -A INPUT -m state --state INVALID -j DROP
...
$IPTABLES -A FORWARD -m state --state INVALID -j LOG --log-prefix "DROP INVALID (FORWARD): "
$IPTABLES -A FORWARD -m state --state INVALID -j DROP

and for the SYN flood stuff, in function load_synflood()

$IPTABLES -A syn_flood -j LOG --log-prefix "SYN FLOOD: "
$IPTABLES -A syn_flood -j DROP

 

Solaris and DNS

Just that I’ll never have to google this one up again….

To get Solaris to make use of your ususal DNS

cp /etc/nsswitch.conf /etc/nsswitch.conf.orig
cp /etc/nsswitch.dns /etc/nsswitch.conf
echo "nameserver xxx.yyy.zzz.bla" >> /etc/resolv.conf
svcadm restart nscd

There we go.

Search for a good audio player

For a long time i’ve been a fan of simple WinAMP-style music players, and went the XMMS -> BMP -> Audacious way. Then, with my collection growing over the years, I got to like library driven players, with Amarok 1.4* being the best regarding music management capabilities.

Running KDE4 I decided to get rid of kdelibs-3 and everything depending on it, inkluding Amarok 1. So I need a new music manager/player.

This is what I tried out so far:

  • Amarok 2

Somehow it looks cool. But managing music isn’t as cool as it was with Amarok1.

  • Banshee

I couldn’t figure out how to simply drag & drop files from the file browser to the play queue

  • Listen

Looks most promising regarding the UI layout and feature set. Unfortunately the libraray can only be one single folder, and well after reading in my 32000 files, Listen was up at consuming 1.2GB RAM and crashed right away when trying to play one. (I used current SVN)

  • XMMS2 + Esperanza

if XMMS2 only had a good ALSA plugin and didn’t exhibit memory leaks after running a day….

  • MPD + Sonata

Actually this combination is just perfect. Really. I easpecially like the "browse library by filesystem" feature. This would be it, if I just could figure out how to add files from the file manager to the current playlist. Drag & drop doesn’t work.

  • Exaile

Really nice too. Tried the 0.3 branch, and I’m really looking forward to it.

Howto: Convert avi/mov/any video to Flash/flv on Linux

Recently I wanted to convert a Quicktime .mov video to Flash .flv in order to post it on this page, for the fun of it.
First thought: uuuh how do I do this on Linux? But it’s pretty simple, thanks to ffmpeg. Works fine with anything that ffmpeg can play, so avi, mpeg, wmv or whatever.

It’s as simple as:

ffmpeg -i input.avi -s 320x240 -ar 44100 -o movie.flv

There is also a nice tool to add metadata info like duration etc to flv files, called flvtool2.

cat movie.flv | flvtool2 -U stdin movie.flv

Now your flv has duration info and is ready for the website.

Bash pattern matching

BASH offers a nice way to replace patterns. Until now I always used basename and a variable.
For example moving all .jpeg files in a folder to .jpg (hey, it’s just an example..)

for moo in *.jpeg; do
    newname="`basename $moo .jpeg`.jpg"
    mv $moo $newname
done

But isn’t that just plain ugly? That one is lot nicer:

for i in *.jpeg; do
    mv "$i" "${i%.*}.jpg"
done

1337

Howto: receive mail and save attachment with fetchmail, procmail and metamail

At work I recently had to set up a solution that periodically checks a POP3 account on our M$ Exchange wannabe mailserver, and saves the attachments to some folder for further processing. As I didn’t find a ready-to-go-solution for this on the web, just snippets here and there, and of course hundrets of other people asking the same, here it is.

You will need

  • fetchmail
  • procmail
  • metamail (or uudeview, see first comment below)

In this example I’ll use a POP3 account, the full mail will be backed up to ~/mail_backup, and attachments will be unpacked to ~/attachments. fetchmail also handles IMAP accounts just fine. Please refer to the fetchmail documentation.

Setting up fetchmail

First create a file $HOME/.fetchmailrc

poll my.pop3.server 
protocol pop3 
user 'myuser' 
password 'mypassword' 
mda '/usr/bin/procmail -d %T'

Setting up procmail and metamail

Then we configure procmail so it forwards the messages to metamail in $HOME/.procmailrc

:0
*^content-Type:
{
        # backup the complete mail first..
        # you can leave out this part if you don't want a backup of the complete mail
        :0c:
        $HOME/mail_backup

        # Now the actual unpacking part
        #
        # this is the place where the attachments will be unpacked to
        METAMAIL_TMPDIR=$HOME/attachments

        # forward to metamail
        :0fw
        | metamail -w -y -x
}

Regarding metamail, we tell it to ignore any mailcap file, so it doesn’t use interpreters (-w), yanking the message and save the content raw (-y) and force it in non-interactive mode (-x).

That’s it about it. We are ready for testing.

Test run

Now we simply fire up fetchmail, the rest should be magic.

fetchmail -kv

HTH