Archive for May, 2007

Aggregate Traffic Used From a Combined Apache Logfile

Tuesday, May 8th, 2007

Today I just wanted to know the traffic sent out by one of our apaches for a certain client. Our administrator came up with the following code that did it - awesome!

#!/bin/sh
for file in [path to your logifes]/*.bz2;
do
    echo -n " $(basename $file) " >> ~/traffic.out;
    bzcat $file | awk ‘BEGIN{ regex="^/clientFolder/";summe=0;} { if (match($7,regex) && $9 == 200) {summe=summe+$10}} END {print summe/1024/1024}’ >> ~/traffic.out ;
done

This script will go through all logfiles and sum up the bytes transfered for all files in the clientFolder.

Typing Special Keys under Linux

Monday, May 7th, 2007

Some special characters like ~ (tilde) cannot be typed by simply pressing the key combination. This is true at least for german keyboard layouts and Ubuntu 6.10 (Edgy Eft) and 7.04 (Feisty Fawn).

To prevent this behaviour and display the character upon the first stroke add the following to you /etc/X11/xorg.conf under the section Input Device for identifier Generic Keyboard:

Option "XkbVariant"  "nodeadkeys"

My section looks like this:

Section "InputDevice"
        Identifier      "Generic Keyboard"
        Driver          "kbd"
        Option          "CoreKeyboard"
        Option          "XkbRules"      "xorg"
        Option          "XkbModel"      "pc105"
        Option          "XkbLayout"     "de"
        Option          "XkbVariant"    "nodeadkeys"
EndSection

How to change encoding of a file?

Sunday, May 6th, 2007

Another chapter of the book “Encoding is hell” ;) Today I noticed that some files in one of our projects suddenly have been converted to UTF-8 where they should have been in ISO-8859-1. Ok, short question: How to convert it back?

Short Answer
Use iconv like this:

iconv –from-code=UTF-8 –to-code=ISO-8859-1 inputfile.txt > outputfile.txt