GNU Screen's hardstatus
Posted by hank, Sat Jul 14 20:17:00 UTC 2007
I use GNU Screen. A lot. I found an article linked from DIgg today that showed me how to use a setting called hardstatus to set the little bar at the bottom to my liking. I decided to mess around with it a bit, and I ended up with this:

It shows my hostname, IP, uptime, screen window number and name, date and time, and load averages. Pretty cool, huh?
This is how you do it:
- First, create a
.screenrcfile and dump this in there:
hardstatus alwayslastline
backtick 1 60 60 /home/hank/.screen_hardstatus
hardstatus string "%{Gk}%H: %{+s y}%1` | %=%n: %t%= | %m/%d %c | %{+b}%l"
- Now, see the line that starts with backtick? That tells screen what program to run for assigning output to
%1`in the hardstatus string. Let’s make the.screen_hardstatusfile as well (make it in your own home directory).
#!/bin/bash
# Script to get run by hardstatus in screen.
# Prints customized single-line system stats
IP=`ifconfig eth0 | grep Mask | cut -d: -f2 | cut -d " " -f1`
UPTIME=`perl -pe 's/^(\d+).*/sprintf("%d", ($1\/(24*3600)))." days"/e' /proc/uptime`
echo -n "$IP | Up: $UPTIME"
I cheated and used perl, but all of this could safely be converted to sed/awk easily. All this does is print my raw dotted quad IP address, a pipe, and then the current uptime in days rounded down.
- Now, just run
screen. You should see something similar to the first picture. I used this page a lot to customize the colors, etc.

Blog Posts