Uptime for bash scripts

if you ever need to get uptime from the command line then I just thought I would share this with you. I searched on the forum and could only find solutions returning undecipherable seconds. Below is formatted in human readable form.

seconds_up=$(ubus call system info | jsonfilter -e "$['uptime']") ; 
date -ud "@$seconds_up" +"$(( $seconds_up/3600/24 )) days %H hours %M minutes %S seconds"

what's wrong with the uptime command ?

root@OpenWrt:~# uptime
 13:41:57 up 6 days, 22:38,  load average: 0.12, 0.11, 0.09
2 Likes

a forum search never offered me uptime so that's a first for me. Maybe uptime is a recent addition (last couple years maybe?). Solutions being offered were circa 2021. Not all wasted though. I think my output a bit cleaner.

it's a vanilla linux command, not unique to openwrt, that's why you didn't find any references to it.

1 Like

yeah...just dawned on me. I am definitely degrading from seasoned down to journeyman.

1 Like