Basically I an using conky to ssh into an android tv box and get the uptime and display it on the conky screen.

I have this so far, found on net and hacked by me but it works, please amend if its crap

uptime | awk -F'( |,|:)+' '{print int($6/7),"weeks",$8,"hours,",$9,"minutes."}'

and it shows

4 weeks 1 hour 1 minute

How do I get

4 weeks **1 day** 1 hour 1 minute

Since you tag your question with Ubuntu, below is enough.

$ uptime -p
up 4 weeks, 1 day, 1 hour, 1 minute

see man uptime for Ubuntu.

-p, --pretty
      show uptime in pretty format

Or with your own script:

awk -F'( |,|:)+' '{
    printf("%dweeks, %.fdays, %dhours, %dminutes\n", 
           $5/7, ($5/7-int($5/7))/0.143+.05, $7, $8)
}' <(uptime)

Each day~=0.143 week, and we divided the result to 0.143 to get days, then added 0.5 and with printf' s .f control it will round to next integer number (does as Ceil function).

You may need to change $5, $7 and $8 with $6, $8 and $9.

| improve this answer | |
  • 1
    Also works on RHEL7 and Fedora 24,. so I suspect it will work in any Linux distro. – NickD Sep 25 '17 at 20:31
  • Thanks : ) Yeah, except OSX, but awk version should work I think in all distros – αғsнιη Sep 25 '17 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.