getting uptime in Weeks, Days, Hours, Minutes

Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
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
linux date uptime
add a comment |Â
up vote
5
down vote
favorite
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
linux date uptime
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
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
linux date uptime
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
linux date uptime
linux date uptime
edited Sep 25 '17 at 21:30
Jeff Schaller
32.3k849110
32.3k849110
asked Sep 25 '17 at 19:48
not_Rich
334
334
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
10
down vote
accepted
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, %dminutesn",
$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.
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, butawkversion should work I think in all distros
â Ã±ÃÂsýù÷
Sep 25 '17 at 20:48
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
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, %dminutesn",
$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.
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, butawkversion should work I think in all distros
â Ã±ÃÂsýù÷
Sep 25 '17 at 20:48
add a comment |Â
up vote
10
down vote
accepted
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, %dminutesn",
$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.
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, butawkversion should work I think in all distros
â Ã±ÃÂsýù÷
Sep 25 '17 at 20:48
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
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, %dminutesn",
$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.
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, %dminutesn",
$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.
edited Sep 26 '17 at 15:27
answered Sep 25 '17 at 20:13
ñÃÂsýù÷
15.7k92563
15.7k92563
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, butawkversion should work I think in all distros
â Ã±ÃÂsýù÷
Sep 25 '17 at 20:48
add a comment |Â
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, butawkversion should work I think in all distros
â Ã±ÃÂsýù÷
Sep 25 '17 at 20:48
1
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
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
Thanks : ) Yeah, except OSX, but
awk version should work I think in all distrosâ Ã±ÃÂsýù÷
Sep 25 '17 at 20:48
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394397%2fgetting-uptime-in-weeks-days-hours-minutes%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password