Sponsored Content
Full Discussion: geekTool
Top Forums UNIX for Dummies Questions & Answers geekTool Post 302216984 by MastaFue on Monday 21st of July 2008 04:59:25 PM
Old 07-21-2008
geekTool

Hello!

Here is my problem:

I try to display the uptime of my computer on my desktop with the help of a tool called GeekTool (for Mac).
I want the uptime output to look like that:
x day(s) y h z min (but if the pc is only running e.g for several minutes it should leave out the day and the hours)
For that reason I using the command "uptime" in a modified version:

uptime | awk '{sub(",", "min ", $5); sub(":", "h ", $5); sub("day,", " day", $4); sub("days,", " days ", $4); sub("mins,", "min", $4); sub("min,", "min", $4); sub("hrs,", "h", $4); sub(":", "h ", $3); sub(",", "min", $3); sub("2", "", $4); sub("1", "", $4); print "uptime : " $3$4$5}'

but this piece of code only works until I reach a uptime of one day or more because than it displays only the day, not the hours and minutes.

So I tried this code

uptime | awk '{sub("2 users", " ", $6); sub(",", " ", $6); sub("mins", "min ", $6); sub(",", "min ", $5); sub(":", "h ", $5); sub("day,", " day", $4); sub("days,", " days ", $4); sub("mins,", "min", $4); sub("min,", "min", $4); sub("hrs,", "h", $4); sub(":", "h ", $3); sub(",", "min", $3); sub("2", "", $4); sub("1", "", $4); print "uptime : " $3$4$5$6}'

But this somehow does not work properly because it shows the number of users currently logged on. so my question is how can I modify my command to display the uptime like that: x day(s) y h z min (no matter how long my computer is turned on)
And is there a niftier command than awk to the same job.
sorry for my weird question but I am new at unix.
I hope someone can help me.
Thank you in advance!
 

We Also Found This Discussion For You

1. UNIX for Dummies Questions & Answers

GeekTool

Hello to whoever is reading this! I try to display my uptime on my desktop with a program called GeekTool. For that purpose I use this command uptime | awk '{print "Uptime : " $3 " " }' So it looks like this Uptime : 3:01, My first question is how to remove the comma behind the... (7 Replies)
Discussion started by: MastaFue
7 Replies
UPTIME(1)							   User Commands							 UPTIME(1)

NAME
uptime - Tell how long the system has been running. SYNOPSIS
uptime [options] DESCRIPTION
uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. This is the same information contained in the header line displayed by w(1). System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time. OPTIONS
-p, --pretty show uptime in pretty format -h, --help display this help text -s, --since system up since, in yyyy-mm-dd MM:HH:SS format -V, --version display version information and exit FILES
/var/run/utmp information about who is currently logged on /proc process information AUTHORS
uptime was written by Larry Greenfield <greenfie@gauss.rutgers.edu> and Michael K. Johnson <johnsonm@sunsite.unc.edu> SEE ALSO
ps(1), top(1), utmp(5), w(1) REPORTING BUGS
Please send bug reports to <procps@freelists.org> procps-ng December 2012 UPTIME(1)
All times are GMT -4. The time now is 10:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy