-
-
Save a2902793/6b40d2bcad494d0cf5c021ae0b61872a to your computer and use it in GitHub Desktop.
Revisions
-
ioagel revised this gist
Nov 10, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ #!/bin/sh # Referenced this stackoverflow answer by John1024: https://stackoverflow.com/a/28353785/2372698 uptime -p >/dev/null 2>&1 -
ioagel revised this gist
Nov 10, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ #!/bin/sh # Referenced this stackoverflow answer: https://stackoverflow.com/a/28353785/2372698 uptime -p >/dev/null 2>&1 -
ioagel created this gist
Nov 10, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/sh uptime -p >/dev/null 2>&1 if [ "$?" -eq 0 ]; then # Supports most Linux distro # when the machine is up for less than '0' minutes then # 'uptime -p' returns ONLY 'up', so we need to set a default value UP_SET_OR_EMPTY=$(uptime -p | awk -F 'up ' '{print $2}') UP=${UP_SET_OR_EMPTY:-'less than a minute'} else # Supports Mac OS X, Debian 7, etc UP=$(uptime | sed -E 's/^[^,]*up *//; s/mins/minutes/; s/hrs?/hours/; s/([[:digit:]]+):0?([[:digit:]]+)/\1 hours, \2 minutes/; s/^1 hours/1 hour/; s/ 1 hours/ 1 hour/; s/min,/minutes,/; s/ 0 minutes,/ less than a minute,/; s/ 1 minutes/ 1 minute/; s/ / /; s/, *[[:digit:]]* users?.*//') fi echo "up $UP"