How to display load average in terminal titlebar

If you’ve managed a number of Linux servers, then you probably know what it’s like to have several terminal windows running top on your desktop.

There is a better way to do this. You can display load average in real time in your terminal titlebar.

Use this script:

#!/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(/ /,<LOAD>);
close(LOAD);
print "\033]0;";
print "$host: $load[0] $load[1] $load[2] at ", scalar(localtime);
print "\007";
sleep 2;
}

Save this as a script called tl, and copy it to your ~/bin directory.

When you’d like to have titlebar replaced with the name, load average, and current time of the machine you’re logged into, just run tl&

When your job is finished, just do: killall tl before logging out.
Or, if you want to automate this, you can try:

$echo 'killall tl > /dev/null 2>&1' >> ~/.bash_logout

That’s all.

 

 


If you liked the post, we should get connected - follow me on Twitter