Jun 142009
 

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 purpse. 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.

 Posted by at 6:34 am