Buffalo Linkstation: Controlling LEDs with microapl

microapl is a wrapper script for micro_evtd, which passes the corresponding hexadecimal value for setting different values of your buffalo linkstation. In my case, debian squeeze was installed onto a Buffalo LS-Pro v1.

There are two types of controlling the leds: With “mcon”, the leds are controlled by the linkstation. With “cpu”, you can set the leds by yourself.

To get all possible settings, type in:

root@box:~ microapl
option: boot_start
boot_end
power_off
shutdown_wait
shutdown_cancel
skip_standby
delay_standby
standby
reboot
temp_get
fan_set_speed [arg]
fan_get_speed
bz_on [arg]
bz_set_freq [arg]
bz_melody tempo note ...
bz_imhere tempo note ...
int_get_switch_status [arg]
led_set_bright [arg]
led_set_cpu_mcon [arg]
led_set_on_off [arg]
led_set_blink [arg]
led_set_code_error [arg]
led_set_code_information [arg]
led_set_cpu_mcon [arg]
mcon_get_status
hdd_set_power [arg]
mcon_get_version

As you see, you can do many cool stuff, for example play a melody with bz_melody, or set and get the fan speed. Just try out.

To get the current controlling type of the leds (cpu or mcon), type in:

root@box:~ microapl -a led_set_cpu_mcon
#[microapl.led_set_cpu_mcon]
led_power=mcon
led_info=mcon
led_diag=mcon
led_link=mcon

If you want to change the diag-led (error, red) by yourself, set the the led_diag value to “cpu”:

root@box:~ microapl -a led_set_cpu_mcon diag
root@box:~ microapl -a led_set_cpu_mcon
#[microapl.led_set_cpu_mcon]
led_power=mcon
led_info=mcon
led_diag=cpu
led_link=mcon

Now the value of led_diag is changed changed to “cpu”. To light up the diag-led, type in:

root@box:~ microapl -a led_set_on_off diag
root@box:~ microapl -a led_set_on_off
#[microapl.led_set_on_off]
led_power=off
led_info=off
led_diag=on
led_link=off

To change the power, link, info and diag led to cpu and light them up, type in:

root@box:~ microapl -a led_set_cpu_mcon power info diag link
root@box:~ microapl -a led_set_on_off power info diag link

To change everything back to mcon (default), just use “off” as parameter:

root@box:~ microapl -a led_set_cpu_mcon off

Have fun!

ESXi Snapshot-Revert Script

In meiner Test-VM stelle ich oft einen vorherigen Snapshot her, um mit Test usw. mit einer leeren Debian Installation zu beginnen. Mit folgendem Script kann ich einen Snapshot direkt aus der Test-VM wiederherstellen, ohne mich im vSphere-Client einloggen zu müssen:

#!/bin/bash
 
host="esxi-host"
vm="test/test.vmx"
 
# get vm-id
vmid=$(ssh $host 'vim-cmd vmsvc/getallvms' | grep "$vm" | awk {'print $1'})
echo "vm-id: $vmid"
 
ssh $host "vim-cmd vmsvc/snapshot.revert $vmid suppressPowerOff && vim-cmd vmsvc/power.on $vmid"

Der Befehl vim-cmd vmsvc/snapshot.revert stellt den ersten Snapshot der VM wieder her. Sollte man verzweigte Snapshots haben, gibt es zusätzlich die optionalen Parameter snapshotLevel und snapshotIndex.

Votaussetzung für das Script ist, dass man über SSH Zugriff auf die Maschine hat (TechMode).

sysbench unter Debian Lenny kompilieren

sysbench downloaden: http://sourceforge.net/projects/sysbench/

Notwendige Pakete:

apt-get install automake libmysqlclient15-dev

Kompilieren:

./configure
sed -i configure.ac -e 's/AC_PROG_LIBTOOL/AC_PROG_RANLIB/' # fix
./autogen.sh # fix
make
make install

Bash-Script um zeitgesteuert Programme zu starten

Wenn man beispielsweise heute um 20:15 Uhr ein bestimmtes Script starten möchte, kommt man meist um ein Crontab nicht herum. Mit diesem kleinen Script übergibt man als Parameter ein Datum und/oder Uhrzeit und das Script wartet dann bis zu diesem Zeitstempel, bevor das Script beendet wird und das darauf folgende Programm gestartet wird – somit spart man sich das aufwändige editieren der Crontab-Files.

Beispiel

Uhrzeit:

root@test:~$ ./tsleep.sh 14:30; reboot
i sleep until 2009-12-12 14:30:00 ...

Datum:

./tsleep.sh 2009-12-24; reboot
i sleep until 2009-12-24 00:00:00 ...

Datum mit Uhrzeit:

root@test:~$ ./tsleep.sh 2009-12-24 13:45:12; reboot
i sleep until 2009-12-24 13:45:12 ...

Funktionsweise

Der Zeitstempel wird in Sekunden umgerechnet und über eine while-Schleife sekündlich mit dem aktuellen Datum abgeprüft. Ist das aktuelle Datum gleich oder älter dem Zeitstempel, wird das Script beendet und das darauf folgende Program gestartet. Als Zeitstempel kann man alles verwenden was date futtert.

Eine alternative wäre die Differenz der aktuellen Zeit und des Zeitstempels in Sekunden umzurechnen und dann sleep zu übergeben. Ob das perfomanter ist – keine Ahnung, mein Script dagegen überlebt auch Zeit-Anpassungen (z.b. rdate/ntpdate), daher habe ich diesen Weg gewählt.

Sollte jemand Fehler finden oder das Script verbessern, würde ich mich freuen, wenn Ihr mir das mitteilt ;).

Script

#!/bin/bash
 
if [[ -z "$1" ]]; then
        echo "Usage: $0 <timestamp>" >&2
        exit 1
elif [[ -z "$2" ]]; then
        date="$1"
else
        date="$1 $2"
fi
 
date_end=$(date --date="$date" +%s 2>/dev/null);
 
if [[ ! $? -eq 0 ]]; then
        echo "error: invalid date" 2>&1
        exit 1
fi
 
if [[ $date_end -le $(date +%s) ]]; then
        echo "error: end time is lower or eqal start time" >&2
        exit 1
fi
 
echo "i sleep until $(date --date="$date" "+%Y-%m-%d %H:%M:%S") ..."
 
while [[ $(date +%s) -le $date_end ]]; do
        sleep 1
done
 
exit 0

Download

Download tsleep.sh

wget http://blog.kevin-k.com/wp-content/uploads/2009/12/tsleep.sh
chmod +x tsleep.sh

at

Alternativ gibt es auch at, das Befehle direkt von Standard-Input oder einer Datei ließt und zu einer bestimmten Uhrzeit ausführt.

Download VMware Server 2 via wget

Its a little bit tricky, but this is how it works:

Get download-url

Go to http://www.vmware.com/go/getserver and login (or register).

get the download-url of the file (right-click…):
vmware download Download VMware Server 2 via wget

Get cookie

To download via wget, you need to get the cookie named “ObSSOCookie” from your browser.
vmware download cookie Download VMware Server 2 via wget

Download via wget

Use this command to download the file:

wget --no-check-certificate --header="Cookie: ObSSOCookie=<content>" "<url>" -O vmware-server.tar.gz

Example:

wget –no-check-certificate –header=”Cookie: ObSSOCookie=content” “https://www.vmware.com/freedownload/p/download.php?product=server20&a=DOWNLOAD_FILE&baseurl=http://download2.vmware.com/software/server/&filename=VMware-server-2.0.1-156745.i386.tar.gz” -O vmware-server.tar.gz

Happy downloading ;).

Installation von VMware Tools auf Debian Lenny

apt-get install build-essential psmisc gcc-4.1 linux-headers-$(uname -r)
tar xfzv VMwareTools-7.8.4-126130.tar.gz
./vmware-tools-distrib/vmware-install.pl
CC=/usr/bin/gcc-4.1 /usr/bin/vmware-config-tools.pl

gcc-4.1 ist notwendig, wenn der Kernel (z.b. aus den Repositories) mit einer anderen GCC Version kompiliert wurde, als auf dem System vorhanden:

Your kernel was built with “gcc” version “4.1.3″, while you are trying to use
“/usr/bin/gcc” version “4.3.2″. This configuration is not recommended and
VMware Tools may crash if you’ll continue. Please try to use exactly same
compiler as one used for building your kernel. Do you want to go with compiler
“/usr/bin/gcc” version “4.3.2″ anyway?

snmpd: cannot open /proc/net/dev or /proc/net/snmp

I get the following message in syslog from snmpd:

Jun 22 17:10:43 test snmpd[9508]: cannot open /proc/net/snmp ...
Jun 22 17:10:45 test snmpd[9508]: cannot open /proc/net/dev ...

The problem is, that snmpd has no rights to access the proc-filesystem to gather information about interfaces and so.

check the rights of the user and group of snmpd:

root@test:~$ cat /proc/$(pidof snmpd)/status | grep -i -e "^[u|g]id"
Uid:    106     106     106     106
Gid:    0       0       0       0

In my case, the problem was that i was running a grsec kernel (stupid default kernel of my root) and access to proc by users was permitted by the kernel.
to change this, you must change your kernel config (see grsecurity for instructions).

another solution is to change the user or group to a special grsec user/group. but event this is not working correct under some distributions, but patching the source code of snmpd may help.