Date: Mon, 5 May 2003 05:00:03 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Peter Leftwich <Hostmaster@Video2Video.Com> Cc: FreeBSD-Questions@freebsd.org Subject: Re: customize the uptime command Message-ID: <20030505020003.GB24519@gothmog.gr> In-Reply-To: <20030504180640.E99631-100000@Www.Video2Video.Com> References: <20030504180640.E99631-100000@Www.Video2Video.Com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2003-05-04 18:11, Peter Leftwich <Hostmaster@Video2Video.Com> wrote:
> $ uptime
> 6:06PM up 15 days, 21:12, 1 user, load averages: 0.06, 0.13, 0.08
>
> I wonder if it is possible to rewrite the uptime command, similar to the
> way you can customize the output of "date" using +%H%M etc...
>
> The reason I ask is that I'd prefer a flag to standardize the format to
> y:m:d:H:M;S or years, months, days, hours, minutes, seconds. Or you could
> have some kind of "--only H" flag which would display the uptime ONLY has
> hours. In my case, the example above, it would be: 381 hours
>
> Is there a fast script out there can reformat the uptime perhaps??
You can always do fancy reformatting of text with awk:
uptime | awk '{
if (match($0, "days,")) {
today = $5;
sub(":.*$", "", today);
hours = 24 * $3 + today;
sub("[0-9]* days,[^,]*,", hours" hours,");
} else {
today=$3;
sub(":.*$", "", today);
sub("up [^,]*,", "up "today" hours,");
}
print;
}'
The above should work for both types of uptime output.
- Giorgos
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030505020003.GB24519>
