Daniels Blog
4Mai/100

Lasse Deine Kiste sprechen, wie in den alten Filmen

Das hier ist ziemlich geekig, aber vielleicht gefällt es ja gerade deshalb. Kein Film in den 60ern, 70er und 80ern in dem ein Computer vorgekommen ist, hat es unterlassen der Kiste eine Stimme zu spendieren. Diese waren meistens (außer natürlich beim Übervisonär Kubrick) ziemlich robotisch. Wäre es nicht toll wenn unsere Rechner uns den ganzen Tag im Robo-Style nerven würden? Sie können! Aber es kann sogar recht nützlich sein, wenn man die Plapperei dezent einsetzt und interessante Dinge als Sprachausgabe sprechen lässt.

Dann mal los:

Man braucht zunächst einmal eine Software für Sprachausgabe. "espeak" ist für den Zweck ziemlich gut geeignet. 80er-Robo-Style und gut konfigurierbar.

sudo apt-get install espeak

Um die Sprachausgaben zu automatisieren habe ich mich für "swatch" entschieden. Swatch ist ein Programm, das Logs live mitliest und beim Auffinden von bestimmten Suchmustern ein externes Programm startet - in unserem Fall espeak.

sudo apt-get install swatch

Jetzt ist alles installiert um einen ersten Laber-Task anzulegen.
Die Kiste (ein Server) soll sprechen, wenn neue Mail ankommt.

Ich benutzte Spamassassin um meine Mail zu filtern. Deshalb erhalte ich solch eine Zeile in /var/log/mail.log. Und zwar jedes Mal, wenn eine neue Mail ankommt:

# /var/log/mail.log
May 03 16:34:04 star spamd[13365]: spamd: clean message (-2.4/0.5) for mailbox:1001 in 1.9 seconds, 7128 bytes.

Nun ist es an der Zeit swatch beizubringen, auf was es achten soll:

# /etc/swatch/ham
watchfor /clean message/
exec "espeak new_mail &"

Nun muss nur noch der Swatch-Daemon gestartet werden:

/usr/bin/swatch --daemon --config-file=/etc/swatch/ham --tail-file=/var/log/mail.log

Ganz simpel. Aber die Möglichkeiten sind endlos. Alles was geloggt wird, kann gesprochen werden. Jetzt hat man alle Tools an der Hand um eine Kiste zu einer absolut nervigen Labertasche zu machen. Viel Spass!

26Mai/080

Making your server box talk like in those old movies

This is a silly geek thing but you might like it. Why not let your penguin-server talk to you when it needs updates or other interesting things happen?

Code and config in these examples are tested on a debian box.

 What we need:
-A software for speech synthesis
espeak is good for this purpose. quiet configurable and the voice quality is OK.

apt-get install espeak

-A software that can trigger events, when certain log entries appear
swatch is our friend here. it reads logs in realtime and triggers a command if a specific pattern is found.
In our case it will just trigger espeak to say something.

apt-get install swatch

Now that we have our tools lets make a sample talker...
We want our box to report, if new (no-spam) mail arrived.

I'm using spamassassin to filter my mail.
I get a line similar to

Jul 26 16:34:04 star spamd[13365]: spamd: clean message (-2.4/0.5) for mailbox:1001 in 1.9 seconds, 7128 bytes.


in /var/log/mail.
log
everytime a good messages reaches my inbox.

So create a config file for swatch to look out for lines like that

File: /etc/swatch/ham

watchfor
/clean message/
exec
"espeak new_mail &"

The only thing left to do now is to start the swatch daemon

/usr/bin/swatch --daemon --config-file=/etc/swatch/ham --tail-file=/var/log/mail.log
I think you got the point. The possibilities are endless. Everything that is logged can be spoken.

But there are other interesting possibilities. Lets say you want your box to report new available updates to you.
This little script can do it when run from a repeating cron-job:


#!/bin/bash
apt-get update
UPDATELINE
=`apt-get --simulate upgrade | grep remove`
EINS=`echo $UPDATELINE | cut -d " " -f 1`
ZWEI=`echo $UPDATELINE | cut -d " " -f 3`
DREI=`echo $UPDATELINE | cut -d " " -f 6`
VIER=`echo $UPDATELINE | cut -d " " -f 10`
((
UPDATES=EINS+ZWEI+DREI+VIER))
if [
$UPDATES -gt 0 ]; then
espeak
"REPORT: i need $UPDATES updates! please install as soon as possible"
fi

Now you have got all the tools to make your server an absolutely anoying brabbling box.
Enjoy.