Idle alerts with bcvi

In case you haven't met it before, bcvi is a crazy backwards tool (written in Perl of course) that lets you type commands on a server to make things happen on your workstation. I've just released an update to the notifications plugin so I thought I'd blog about it here.

Here's a simple example to illustrate what the notifications plugin does. Imagine you've SSH'd into a server to kick off some long running command and you'd like to be notified when the command finishes. In this example, I'm running a database restore:

$ pg_restore -d acmecrm crm.pgdump; bnotify 'DB is restored!'

When the pg_restore completes, the bnotify command will be run. Bnotify is an alias for bcvi which will send a message back to your workstation to pop up a desktop notification.

The new feature is that bnotify now accepts a --idle option to send you a notification when the TTY is idle. The reason I wanted this is that I'm currently doing a bunch of server upgrades and although the upgrade process mostly runs unattended, I do get prompted for questions at intervals. Here's how I use the new feature:

$ bnotify --idle
Starting background process to monitor /dev/pts/0 for 20 second idle period
Kill monitor with: bnotify --kill
$ sudo apt-get dist-upgrade
[sudo] password for grant: 
Reading package lists... Done
Building dependency tree       
The following NEW packages will be installed:

I will then leave the upgrade running and switch to do something in another window (or desktop). Some time later, the upgrade process will either complete or will pause to ask me how I'd like to deal with a possible conflict with a new version of a config file that wants to replace one I've modified. Either way, bnotify will notice that there's been no output on the terminal for some amount of time (default 20 seconds) and will signal my workstation to alert me with a message: "Notification from [servername]. Terminal is idle".

In my case, the workstation end of the notifications process is handled by Desktop::Notify - which works on Linux desktops (e.g. Gnome2/3, XFCE, KDE probably). But you could replace that with something that talked to Growl on a Mac.



Hi Grant,

Awesome! Thanks for providing this. However I have a little problem using this apps. When doing bcvi file_to_edit, it fails with error "The $BCVI_CONF environment variable has not been set" eventhough I've followed the installation instruction.

File .bashrc has also been modified correctly both on my laptop and the remote server. What might have caused it?


To answer my own question... after debugging it turns out that I have TERM variable reset on the remote server via .bashrc thus bcvi finds the environment variable $BCVI_CONF empty when doing --unpack-term.

I needed to reset the TERM variable to 'xterm' on the remote server is because it's an old RHEL server that doesn't support xterm-256colors (default TERM in my workstation).

Now that BCVI works, I don't have to reset $TERM again as I can edit the file locally using my vim configuration.

Thanks for the great work Grant!

Leave a comment

About Grant McLean

user-pic Perl hacker since 1995. Coordinator of in New Zealand.