Created
May 3, 2024 13:56
-
-
Save luckman212/a46f62f247bfcf46ba03faf83f3b88cb to your computer and use it in GitHub Desktop.
poor man's uptime on macOS by parsing JSON output of system_profiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system_profiler SPSoftwareDataType -json | | |
jq --raw-output --argjson labels '[ "day", "hour", "minute", "second" ]' ' | |
.SPSoftwareDataType[0].uptime[3:] // empty | split(":") as $uptime | | |
def pprint: | |
($uptime[.] | tonumber) as $val | | |
if $val == 0 then empty else | |
"\($val) \($labels[.])" + (if $val == 1 then "" else "s" end) | |
end; | |
[range($uptime|length)] | map(pprint) | join(", ")' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related SO post: https://stackoverflow.com/a/78425192/617864