This is The homepage of Alexander Kostadinov

This is a simple blog of some things I've done since 2006

Email me to avalon_at_friendofpooh_dot_company


Some very interesting/important info I've found.

HDD benchmark using hdparm to change drive options.

I read http://www.linuxdevcenter.com/pub/a/linux/2000/06/29/hdparm.html and I made my own tests, which show that important are DMA and write cache.
First I see the info from HDDs. I set some features and run test which is #dd if=/dev/zero of=/dev/hdx. See the scripts in the end of the file. See my test:
Test Setup and Result File



Monitoring Proxima Tsunami MP.11 with MRTG

Updated 31.10.2006

I have connected few Proxima Tsunami MP.11 wireless units and
I needed a way to monitor them.

See how it looks like.

The config script is written on php.
Monitoring scripts use only snmpget, dc and bash, so you must care
which version of snmp-utils you are using.
Also check the PATH variable at the beginning of the scripts.
See README for more instructions.

These scripts work only if you have single Tsunami Base Station and single Sattelite Station for each link, because for each device I use OriWORPIfStatTableEntry table (view mib file) for the 3th interface of the device (the wireless interface). If you have more sattelite stations, you have to use the same script for them, but for the base station you must use entries in the OriWORPIfSatStatTableEntry table. Every link is indexed, so to monitor noise use for example oriWORPIfSatStatTableAverageLocalNoise.2 for the second link. The other way is to monitor each link by querying only sattelite devices and reverse oriWORPIfStatTableAverageLocalNoise.3 with oriWORPIfStatTableAverageRemoteNoise.3 for the base station.

With this updated version you could easily implement the latter workaround.

Config and monitoring scripts, orinoco.mib and README


BASH Programming Lesson 0

You can substract unsigned integer from unsigned integer using
signed integer using BASH if you know that the result will fit
signed integer. (signed=uns1-uns2)
Not tested on non intel architecture.
In this example I asume uns1>uns2. You have to change conditions
if this is not true in your case:

        (($uns1>=0)) || (($uns2<0)) && signed=$(( $uns1-$uns2 )) || \
        signed=$(( 1+(2147483647-$uns2)+(2147483647+$uns1)+1 ))
	

This is perfectly useful if you are braindead.



BASH Programming Lesson 1

You can compare two numbers as string with bash using a function.
In my example numbers must be unsigned, but it is possible to
modify the code as you wish.

	function strcmp() {
    	    local i=$1
    	    local j=$2
    	    (( ${#i} < ${#j} )) && return 2;
    	    (( ${#i} > ${#j} )) && return 1;
    	    [[ "$i" == "$j" ]] && return 0;
    	    [[ $i<$j ]] && return 2;
    	    [[ $i>$j ]] && return 1;
        }
	

Use the function for example this way:

 
	strcmp $int1 $int2;
	(( $? == 1 )) && dosomething;
	



BASH Programming Lesson 2

Using bash you can split string on words and make whatever you wish. It is possible to use things explained in "Parameter Expansion" section in the bash man page to do everything with strings, but I will explain simple/easy word splitting using all kind of white spaces as separator (or something set in the $IFS variable).
I didn't managed to use "echo $string | read ..." for the reason that both commands are shell built-in. If you enclose the read in brackets it will work as expected (but in a subshell and you'll need to echo it after all). Anyway better example is comming.
For example we have string "word1 word2 word3" in $string.
We need $rez to be "word2 word3".
Here is the code:

	function getresult() {
	    shift;
	    rez=$*
	}
	getrez $string;		
	

Be smart and write code to suit your needs.



Chrooting BOINC

You can chroot boinc client. See how. I used version 5.2.13 and made the following:

	./boinc_self_extractor
	cd BOINC
	useradd boinc
	chown -R boinc .
	mkdir -p /var/boinc/etc
	mv * /var/boinc
	mkdir /var/boinc/dev
	mkdir /var/boinc/proc
	mkdir /var/boinc/lib
	cp -a /dev/null /dev/random /dev/urandom /dev/zero /var/boinc/dev
	cd /etc
	cp group  host.conf  hosts  localtime  nsswitch.conf  passwd  resolv.conf /var/boinc/etc
	cd /var/boinc/etc
	mcedit passwd
	mcedit group
	mcedit what_you_need
	cd /lib
	cp ld-linux.so.2 libnsl.so.1 libnss_dns.so.2 libnss_hesiod.so.2 libnss_nisplus.so.2 /var/boinc/lib
	cp libc.so.6 libnss_compat.so.2 libpthread.so.0 libdl.so.2 libresolv.so.2 libm.so.6 /var/boinc/lib
	cp any_other_libs_shown_with_ldd /var/boinc/lib
	

You can now create scripts to run the applications. Note that you may need the compartment utility or use a similar one.
The first one is to run the client:

	#!/bin/bash
	dir="/var/boinc"
	cat /proc/cpuinfo > $dir/proc/cpuinfo
	cat /proc/meminfo > $dir/proc/meminfo
	exec compartment --user boinc --chroot $dir boinc $*
	

The second script is for the boinc_cmd. If you need the manager I guess it is easier to copy the file with the password to a location known to the manager and not chroot it or connect to the client from another host...

	#!/bin/bash
	exec compartment --user boinc --chroot /var/boinc boinc_cmd $*
	



OpenWRT WDS+WPA+AES

I finally managed to get it working...

HARDWARE: WAP54G v1.0
SOFTWARE: White RUSSIAN RC4
REQUIRED PACKAGEs: nas (Yes, the official! ipkg install nas)

Here are my wl0 variables. They are all the same for both devices and only wl0_wds must differ. Relevant are:
wl0_wds_wpa_psk
wl0_wpa_psk
wl0_wds_akm
wl0_akm
wl0_wds_crypto
wl0_crypto

NOTE that to have wpa working, you need only these WITHOUT "wds". To have wpa working on the wds link you MUST specify all "wds" containing variables even if they are tha same as the other. Here I post all other variables I have. wds-wpa-aes.cfg

Tip 1: To have wds working at all, you may need to NOT use lazy_wds!
Tip 2: May need to set wl0_auth_mode to radius or psk to be able to use psk2 or wpa2 (see openwrt wiki for many answers).
Tip 3: To generate 60 digit hex keys you can use php file as this:

	<?php
	for ($i=1; $i<=60; $i++) {
	    $a=rand(0,15);
	    echo dechex($a);
	}
	echo "\n";
	?>
	



MySQL backup using snapshot capable file system

If you use mysql and want regular backup, you probably prefer not to interrupt users. You also want consistent data. With a snapshot capable filesystem or on top of LVM, EVMS or abnything else you could stop the server, snapshot and start the server again. After that you can backup and at last remove the backup. This will introduse some problems with applications that will lose the connection to the server in the mean time. This is in rare cases fatal, but if you want to be extra sure you should "flush tables with read lock", snapshot and "unlock tables".

So I wrote a php script which basically "flush tables with read lock", echoes it's PID and goes to background waiting to be killed to unlock tables. It is intended to be used within a shell script in place of rc.mysql stop and start. Please read instructions into the script itself, because it requires pcntl and posix modules in php cli or cgi sapi. There is also usage information depending on php version/bug.
Download from
here.



Kernel Packet Traveling Diagram

This Diagram I've got from http://www.docum.org/docum.org/kptd/ but think it is cool and wanted to copy it here, so it not get lost for some reason.
DIAGRAM



Routing through two ISPs

The main idea is from the Linux advanced routing and traffic control howto but the example there is ugly. Here I have two other more useful examples (router + some clients).
Example 1
Example 2
In the first example specific is that we specify the networks that will be routed as normal no matter what IP we use (from provider 1 or 2). You see that we can specify larger networks for convinience (10.0.0.0/8 instead of all 10. networks we use).
In the second example we don't specify this, but we increase the priority of the lookup in table main. That could be problematic in some cases, but you could add other rules at the end to handle the problematic networks.



Large and custom fonts

bitedit-0.9.4.tar.gz is a program to hack console fonts with.
I have here some large fonts. I'll try someday to create a cyrilic derivate from them. See them.