Commit Diff


commit - d9a3ff937b28b3aa077047a2a63c829e65b5d3b7
commit + bb204e21bb787b0815ec3d5ece3e24ce5a1e5270
blob - /dev/null
blob + 3e4446989b7f7ca6936d2ce634021d1c3cd79b04 (mode 644)
--- /dev/null
+++ ticks.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# Copyright (c) 2019 Mischa Peters <mischa @ openbsd.amsterdam>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+HOST="s1.obsda.ms"
+
+#15259107187 / 8640000 = days (+remainder) = 176.6107855324074
+#0.6107855324074 * 24 = hours (+remainder) = 14.65885277777778
+#0.65885277777778 * 60 = minutes (+remainder) = 39.53116666666667
+#0.53116666666667 * 60 = seconds.milliseconds = 31.87
+
+echo
+TICKS=$(snmpctl snmp get ${HOST} oid hrSystemUptime.0 | cut -d= -f2)
+echo "TICKS: $TICKS"
+
+TICKS="1193085988"
+
+DAYS=$(echo "${TICKS}/8640000" | bc -l)
+echo "DAYS_REM: ${DAYS##*.}"
+echo "DAYS: ${DAYS%.*}"
+
+HOURS=$(echo "0.${DAYS##*.} * 24" | bc -l)
+echo "HOURS: ${HOURS}"
+echo "HOURS: ${HOURS%.*}"
+echo "HOURS: ${HOURS##*.}"
+
+MINUTES=$(echo "0.${HOURS##*.} * 60" | bc -l)
+echo "MINUTES: ${MINUTES}"
+echo "MINUTES: ${MINUTES%.*}"
+echo "MINUTES: ${MINUTES##*.}"
+
+SECS=$(echo "0.${MINUTES##*.} * 60" | bc -l)
+echo "SECONDS: ${SECS}"
+echo "SECONDS: ${SECS%.*}"
+echo "SECONDS: ${SECS##*.}"
+
+test -n "$DAYS" && printf "%s days, " "${DAYS%.*}"
+printf '%02d:%02d:%02d\n' "${HOURS%.*}" "${MINUTES%.*}" "${SECS%.*}"
+