3 2c6743b8 2022-09-24 mischa # Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
5 bb204e21 2020-05-31 mischa # Permission to use, copy, modify, and distribute this software for any
6 bb204e21 2020-05-31 mischa # purpose with or without fee is hereby granted, provided that the above
7 bb204e21 2020-05-31 mischa # copyright notice and this permission notice appear in all copies.
9 bb204e21 2020-05-31 mischa # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 bb204e21 2020-05-31 mischa # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 bb204e21 2020-05-31 mischa # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 bb204e21 2020-05-31 mischa # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 bb204e21 2020-05-31 mischa # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 bb204e21 2020-05-31 mischa # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 bb204e21 2020-05-31 mischa # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 bb204e21 2020-05-31 mischa HOST="s1.obsda.ms"
18 2c6743b8 2022-09-24 mischa AUTHPASS="tropic shark reefs"
19 2c6743b8 2022-09-24 mischa USER="random"
20 2c6743b8 2022-09-24 mischa PRIVPASS="equ5xerhiffid7klevuk"
22 bb204e21 2020-05-31 mischa #15259107187 / 8640000 = days (+remainder) = 176.6107855324074
23 bb204e21 2020-05-31 mischa #0.6107855324074 * 24 = hours (+remainder) = 14.65885277777778
24 bb204e21 2020-05-31 mischa #0.65885277777778 * 60 = minutes (+remainder) = 39.53116666666667
25 bb204e21 2020-05-31 mischa #0.53116666666667 * 60 = seconds.milliseconds = 31.87
28 2c6743b8 2022-09-24 mischa TICKS=$(snmp get -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
29 bb204e21 2020-05-31 mischa echo "TICKS: $TICKS"
31 bb204e21 2020-05-31 mischa TICKS="1193085988"
33 bb204e21 2020-05-31 mischa DAYS=$(echo "${TICKS}/8640000" | bc -l)
34 bb204e21 2020-05-31 mischa echo "DAYS_REM: ${DAYS##*.}"
35 bb204e21 2020-05-31 mischa echo "DAYS: ${DAYS%.*}"
37 bb204e21 2020-05-31 mischa HOURS=$(echo "0.${DAYS##*.} * 24" | bc -l)
38 bb204e21 2020-05-31 mischa echo "HOURS: ${HOURS}"
39 bb204e21 2020-05-31 mischa echo "HOURS: ${HOURS%.*}"
40 bb204e21 2020-05-31 mischa echo "HOURS: ${HOURS##*.}"
42 bb204e21 2020-05-31 mischa MINUTES=$(echo "0.${HOURS##*.} * 60" | bc -l)
43 bb204e21 2020-05-31 mischa echo "MINUTES: ${MINUTES}"
44 bb204e21 2020-05-31 mischa echo "MINUTES: ${MINUTES%.*}"
45 bb204e21 2020-05-31 mischa echo "MINUTES: ${MINUTES##*.}"
47 bb204e21 2020-05-31 mischa SECS=$(echo "0.${MINUTES##*.} * 60" | bc -l)
48 bb204e21 2020-05-31 mischa echo "SECONDS: ${SECS}"
49 bb204e21 2020-05-31 mischa echo "SECONDS: ${SECS%.*}"
50 bb204e21 2020-05-31 mischa echo "SECONDS: ${SECS##*.}"
52 bb204e21 2020-05-31 mischa test -n "$DAYS" && printf "%s days, " "${DAYS%.*}"
53 bb204e21 2020-05-31 mischa printf '%02d:%02d:%02d\n' "${HOURS%.*}" "${MINUTES%.*}" "${SECS%.*}"