Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-21-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
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!
Sponsored Links
    #2  
Old 07-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
change title of post

is there nobody out there who knows how to modify the uptime command?

I would rename the title of the post if I could maybe more people would respond to a title like "uptime" but i don`t know if that is possible.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
GeekTool MastaFue UNIX for Dummies Questions & Answers 7 04-26-2008 03:14 PM



All times are GMT -4. The time now is 04:02 AM.