Last active
March 20, 2024 15:51
-
-
Save timsutton/9e31a77a92607dcceb5386cbad6bae3e to your computer and use it in GitHub Desktop.
Simple uptime in pure macOS shell
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
#!/bin/bash | |
set -eu -o pipefail | |
function machine_uptime_seconds() { | |
boottime=$(sysctl -n kern.boottime | perl -n -e'/^.* sec = (\d+)?\,.*$/; print $1') | |
now=$(date +%s) | |
uptime=$((now - boottime)) | |
echo $uptime | |
} | |
machine_uptime_seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment