Pages

Friday, December 1, 2006

UD and SED

For those of you who are not familiar with it, "ud" is an uptime daemon that creates an HTML page using a template file which displays the current and the three longest uptimes for a machine. But while it's easy to create an html file, it's not so easy to use it & the data it maintains elsewise. It does have a command line option to display the information, but it's not formated very well...


This is the output of the command line option:
- Uptime for sffpc -
Now : 18 day(s), 01:46:29 running Linux 2.6.8-2-686
One : 117 day(s), 00:27:39 running Linux 2.6.8-2-686, ended Tue Apr 18 08:57:00 2006
Two : 64 day(s), 13:35:38 running Linux 2.4.24-1-686, ended Wed Jun 23 23:10:33 2004
Three: 62 day(s), 05:26:58 running Linux 2.4.27-1-686, ended Sat Nov 27 13:59:06 2004
I originally thought of useing Perl to modify it to my liking but that is a bit overkill. I've not used sed (stream editor) much, but have been curious about it; so decided to see what I could come up with using it, and came up with this (which could use some tweaking, but works):
/usr/bin/ud -d |sed -f $ADMDIR/sed-ud.txt > $TXTMSG
And sed-ud.txt contains the following:
s/running/ (hours:mins:secs)/g
s/Linux.*//g
1s/sffpc/ftn.rocasa.us/
2s/Now /Current /
3s/One /Highest /
4s/Two /Second Highest/
5s/Three/Third Highest /
Which creates the following:
- Uptime for ftn.rocasa.us -
Current : 18 day(s), 01:52:56 (hours:mins:secs)
Highest : 117 day(s), 00:27:39 (hours:mins:secs)
Second Highest: 64 day(s), 13:35:38 (hours:mins:secs)
Third Highest : 62 day(s), 05:26:58 (hours:mins:secs)

No comments:

Post a Comment