Skip to content

Instantly share code, notes, and snippets.

@timsutton
Last active March 20, 2024 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timsutton/9e31a77a92607dcceb5386cbad6bae3e to your computer and use it in GitHub Desktop.
Save timsutton/9e31a77a92607dcceb5386cbad6bae3e to your computer and use it in GitHub Desktop.
Simple uptime in pure macOS shell
#!/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