For a better solution, see this article – I am keeping this post online because it makes it possible to implement distributed notifications with Perl modules included in the Ubuntu repositories.
One of the things lacking (in my opinion at least) when using Irssi and GNU Screen is the lack of a way for Irssi to alert you when you are not looking at the terminal.
I have looked at many implementations for libnotify (default in Ubuntu), Mumbles (Growl for Linux) and Dzen.
Some of the things I have looked at
- thl’s irssi notification script aka fnotify
Most of this is actually quite good and has formed the basis for my implemenation. Uses libnotify.
- Using irssi with libnotify over Secure Shell
A different implementation of the above, using xterm’s print facility to send data to libnotify.
Uses notify-send on the same machine as irssi, requires X-forwarding (which is a bitch with screen). I liked this but as it uses X-Windows on the remote server the notifications might not match those of your desktop
- Dzen notifications
This is where I got the idea for using a named pipe
I used this before libnotify became standard in Ubuntu. It was hard to make it work and required several (Python) daemon running to forward the notifications.
Since I have several machines I use to access my server where Irssi is running none of the other implementations I looked at really worked since I need to be sure that all machines get the notifications. In the end I decided to use MySQL as a “proxy” for the notifications.
Prepare the MySQL database
It’s a good idea to set up a separate database – just in case one of the scripts f*ck up and deletes everything.
$ sudo mysqladmin -u root -p create irssi
mysql> use irssi Database changed mysql> CREATE TABLE `notify` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `summary` varchar(64) CHARACTER SET utf8 NOT NULL, `message` varchar(255) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM; mysql> GRANT ALL ON irssi.* TO 'irssi'@'localhost' IDENTIFIED BY 'Password';
Installing the Irssi script
It is also possible to simply create a table inside an existing database; just adjust the configuration values in Irssi.
The Irssi script is based on Jared Quins work (which in turn is based on irssi-libnotify). The basic idea is the same as with fnotify but instead of writing to a temporary file I write to a MySQL database.
Download the script to
~/.irssi/scripts and rename it to notifier.pl.
If you want it to load automatically, symlink it to
$ ln -sf ~/.irssi/scripts/notifier.pl ~/.irssi/scripts/autorun/notifier.pl
Load the script inside irssi:
/script load notifier.
Once you have loaded the script, set these variables inside Irssi (adjust according to your setup)
/set notifier_mysql_db irssi /set notifier_mysql_host localhost /set notifier_mysql_user irssi /set notifier_mysql_password Password
Setup MySQL port forwarding
It is possible to use autossh to automatically setup the tunnel but since I am always connected to my server (at least when I am in front of a computer) I chose to use normal ssh port forwarding.
~/.ssh/config I have
Host my.server.bogus LocalForward 13306 localhost:3306
The stuff running on your local machine
That is, the stuff that actually shows the notifications
I did not want to bother trying to make the MySQL-stuff error proof so I simply call the Perl script from a shell script like so
Save the script as
The Perl script requires DBI and Desktop::Notify – Both are available in Ubuntu
$ sudo install libdesktop-notify-perl libdbd-mysql-perl
Save the script as
Remember to make both scripts executable.
The final thing to do is to add the notify client to your desktop environment’s autostart
In GNOME: System → Preferences → Startup Applications