Joined: 22 Jul 2003
|Posted: Thu Jan 29, 2004 11:31 pm Post subject: Using Swatch and Speechd to notify you when things happen
|I decided to write this HOWTO as a big thank-you to the Gentoo Forums for always providing me with the answers. Hopefully not too infested with grammatical and other errors.
Changes need to be done, I noticed that the lousy grep patterns below don't see the difference between a FTP login and a "new session" opened on a local console... must...get some sleep
I'm constantly working to get these bloody off-on-off-on (0101)- (machines working for me instead of the other way around.
Below is what I've achieved today while trying to gain yet more control over the computer.
It's not very refined, I'm still very much the noob when it comes to programming moist-evaporators...This is very much work in progress and I hope others have tips and ideas to come with.
My laptop now beeps subtly when I plug in the network cable. It then checks if it is online, if so, it says so (using the speechd/festival-speech emulator (would be nice with some other "codecs" like RealSpeak))
To this network-cable plugged/unplugged thing I will probably add alot of features. I tend to hook up alot of strange network cables wherever I am visiting, and it would be nice to have the computer automatically do whatever it should do depending or where I am.
Whenever someone logs in with SSH/FTP the computer tells me who. If someone tries to log in with the wrong password I hear a sublte beep (R2D2 actually) I havn't made it to tell me who (and from where) because it is usually just me and my lousy typing. Will look into more of these things later (vnc-logins for instance...)
here's what I did:
1. emerge swatch (Description: Perl-based system log watcher)
2. emerge speechd, if you don't already have it, theres a big discussion-thread on it on here somewhere
I was playing around with regexes in metalog.conf but someone told me about swatch... As so often, a quick glance at the man-pages almost had made me not try it, but I quickly noticed that it is very easy and intuitive to use.
watchfor = /link up/
exec=play -v 0.3 /pub/sounds/noise_beepbop.wav
watchfor = /link down/
exec=play -v 0.3 -r 6500 /pub/sounds/noise_beepbop.wav
watchfor = /Accepted password/
exec="play -v 0.3 /pub/sounds/R2-D2_06.wav"
watchfor = /session opened for user/
exec="play -v 0.3 /pub/sounds/R2-D2_06.wav"
watchfor = /sshd/
ignore = /.*/
How to run it:
swatch --tail-file /var/log/everything/current
I havn't still figured out the best way to actually run it. I don't think it will notice when metalog rotates the logfile, starts writing a new file and will keep looking at the old log file. Will see. It would be ideal to pipe the log directly from metalog to swatch, but I don't know if it is possible...
In the .swatchrc above you can see that it sometimes points to the script /pub/scripts/whologin with the arguments ssh or ftp (will add more later)
Below is the very simple script (its the most advanced bashcode I can write, so as you can see I'm no coder) I even had to nag for help from others to learn this magic...
case "$1" in
echo SSH login detected by `tail -n 2 /var/log/everything/current |grep "Accepted password$
echo FTP login detected by `tail -n 2 /var/log/everything/current |grep "(ftp) session op$
play -v 0.1 "/pub/sounds/R2-D2 04.wav"&
#echo Failed login attempt by `tail -n 2 /var/log/everything/current |grep "Failed passw$
.swatchrc also calls for "amionline" which I put together, not unlike two duplo-parts (those big lego's you know?) while going through my directory "of shellscripts, and pieces of scripts and tips and tricks" (spells?)
ping -i 1 -c 2 100777.com | grep time | grep -vq grep && play -v 0.1 "/pub/sounds/noise_b
eeeep.wav" && echo Connected to the internet |festival --tts|| echo "offline"
It simply pings a site; if it receives replies it plays a soundfile and tells me I'm online.
BTW: I also accidentally made a toggle script for gentoo services, I'm sure there's a more refined way to do it.
/etc/init.d/net.eth0 status |grep started |grep -vq grep && /etc/init.d/net.eth0 stop || /etc/init.d/net.eth0 start
cybe bows thankfully to the unix pipe |
Thats about it. Future additions are easy to add to this setup, I have a few ideas. I already have .procmail +osd + gmsgr to effectively notify me of incoming mail in various ways but thats another story. One can add notification of battery status, cpu temperatures, diskspace (that one's kinda important)... etc etc.
The MOST important book on the planet?