I modified a neat little hack, borrowed from Linux Server Hacks
(O’Reilly), so that whenever I ssh into my server, I can monitor the load
from the title bar of the terminal I’m using.

So, here’s the hack, as the book presents it:

$ cat ~/bin/tl
#!/usr/bin/perl -w

use strict;
$|++;

my $host=`/bin/hostname`;
chomp $host;

while(1) {

open(LOAD,”/proc/loadavg”) || die “Couldn’t open /proc/loadavg: $!\n”;

my @load=split(/ /,);
close(LOAD);

print “\033]0;”;
print “$host: $load[0] $load[1] $load[2] at “, scalar(localtime);
print “\007″;

sleep 2;

}

As you can see above, this is a perl script that I’ve placed in my user’s
bin directory. I’ve chmod’d it to have executable permissions:

# chmod +x ~/bin/tl

Now, if I want to see the server load in the title bar whenever I log into
my server through SSH, all I have to do is add this line to my .bashrc:

tl&

This effectively runs the process and backgrounds it, leaving me at the
shell prompt. You can see the backgrounding here:

$ jobs
[1]+ Running tl &

Now, if I simply close the SSH session, the terminal will hang, because
it’s waiting on the tl process to finish. The perfect while loop in the
script causes this to never happen. So, I added this line to my
.bash_logout file in my home directory:

/usr/bin/killall tl

This will kill all running tl processes before closing the bash shell and
terminating the SSH session.

/cs