I’ve got a guestbook of sorts on my XS, but don’t really pay any attention to it. What if someone dropped me a note and I didn’t know about it? Or even worse, what if someone posted something obnoxious that needed to be deleted immediately?
Let me use incron to monitor the guestbook and then notify me via Statusnet when someone posts something. First I install a couple of things:
yum install incron inotify-tools
Now I set up a little notification script in my ~/bin called guestbook-notify and chmod +x it.
#!/bin/bash
curl -u user:pass http://myserver/statusnet/api/statuses/update.xml -d status=”Someone signed the guestbook on `date`” >/dev/null 2>&1
(Where user:pass are my Statusnet username and password.)
Since nano is so easy to use, I’m going to use that to edit the incrontab. This is pretty much like editing the crontab except I’ve read that putting comments in there might cause problems.
export EDITOR=nano
Now I simply
incrontab -e
And put in the entry that’ll watch for the guestbook file to be modified.
/var/www/html/guestbook/guestbook.db IN_MODIFY guestbook-notify
When incron detects that guestbook.db (it’s not really a database, it’s a flat text file from a simple PHP based guestbook) has been modified, it runs guestbook-notify to post to Statusnet, alerting me to take a look.
Since I’ve got the Statusnet XMPP bot running, I also receive the notifications in my Jabber client.
I could make the guestbook-notify command a little more complicated; for example using awk to get the signer’s name out of guestbook.db for the Statusnet post, but this is good enough for now.
References:
http://linux.die.net/man/5/incrontab
http://www.infoq.com/articles/inotify-linux-file-system-event-monitoring
Yes, of course the guestbook-notify script runs when the admin deletes a post off the guestbook, as that is a file modification.
It was bothering me, so here's my new guestbook-notify script that posts to Statusnet with the Name and Message. I created a guestbook Statusnet user just for this.
#!/bin/bash
GUESTBOOK="/var/www/html/guestbook/guestbook.db"
GUEST=`awk "-F::" 'END{print $1}' $GUESTBOOK`
MESSAGE=`awk "-F::" 'END{print $6}' $GUESTBOOK`
STATUS="$GUEST says $MESSAGE"
curl -u guestbook:pass http://myserver/statusnet/api/statuses/update.xml -d status="$STATUS" >/dev/null 2>&1
In case anyone is wondering, I'm using this for a guestbook. It doesn't require MySQL, so I wanted to try it out as an alternative for the XSXO, as MySQL doesn't work well on that little machine.
http://sourceforge.net/projects/flatphpbook/