3 2c6743b8 2022-09-24 mischa # Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
5 2c06b26b 2020-05-31 mischa # Permission to use, copy, modify, and distribute this software for any
6 2c06b26b 2020-05-31 mischa # purpose with or without fee is hereby granted, provided that the above
7 2c06b26b 2020-05-31 mischa # copyright notice and this permission notice appear in all copies.
9 2c06b26b 2020-05-31 mischa # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2c06b26b 2020-05-31 mischa # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2c06b26b 2020-05-31 mischa # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2c06b26b 2020-05-31 mischa # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2c06b26b 2020-05-31 mischa # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2c06b26b 2020-05-31 mischa # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2c06b26b 2020-05-31 mischa # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 6154cf32 2019-03-12 mischa test -n "$1" || exit 1
19 2c6743b8 2022-09-24 mischa AUTHPASS="tropic shark reefs"
20 2c6743b8 2022-09-24 mischa USER="random"
21 2c6743b8 2022-09-24 mischa PRIVPASS="equ5xerhiffid7klevuk"
22 6154cf32 2019-03-12 mischa UPTIMEINFO="/tmp/${HOST}-uptime.txt"
24 86ad8e4b 2019-05-04 mischa rm -rf ${UPTIMEINFO}
25 2c6743b8 2022-09-24 mischa TICKS=$(snmp get -A "${AUTHPASS}" -l authPriv -u ${USER} -X "${PRIVPASS}" ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
26 6154cf32 2019-03-12 mischa DAYS=$(echo "${TICKS}/8640000" | bc -l)
27 6154cf32 2019-03-12 mischa HOURS=$(echo "0.${DAYS##*.} * 24" | bc -l)
28 6154cf32 2019-03-12 mischa MINUTES=$(echo "0.${HOURS##*.} * 60" | bc -l)
29 6154cf32 2019-03-12 mischa SECS=$(echo "0.${MINUTES##*.} * 60" | bc -l)
30 86ad8e4b 2019-05-04 mischa test -n "${DAYS%.*}" && printf '%s days, ' "${DAYS%.*}" > ${UPTIMEINFO}
31 6154cf32 2019-03-12 mischa printf '%02d\\:%02d\\:%02d\n' "${HOURS%.*}" "${MINUTES%.*}" "${SECS%.*}" >> ${UPTIMEINFO}