Blame


1 6154cf32 2019-03-12 mischa #!/bin/sh
2 6154cf32 2019-03-12 mischa #
3 d6cb721e 2021-04-23 mischa # Copyright (c) 2019-2021 Mischa Peters <mischa @ openbsd.amsterdam>
4 6154cf32 2019-03-12 mischa #
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.
8 2c06b26b 2020-05-31 mischa #
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.
16 2c06b26b 2020-05-31 mischa #
17 6154cf32 2019-03-12 mischa test -n "$1" || exit 1
18 6154cf32 2019-03-12 mischa HOST="$1"
19 6154cf32 2019-03-12 mischa COMMUNITY="public"
20 6154cf32 2019-03-12 mischa UPTIMEINFO="/tmp/${HOST}-uptime.txt"
21 6154cf32 2019-03-12 mischa
22 86ad8e4b 2019-05-04 mischa rm -rf ${UPTIMEINFO}
23 d6cb721e 2021-04-23 mischa TICKS=$(snmp get -c ${COMMUNITY} ${HOST} hrSystemUptime.0 | awk -F"[()]" '{print $2}')
24 6154cf32 2019-03-12 mischa DAYS=$(echo "${TICKS}/8640000" | bc -l)
25 6154cf32 2019-03-12 mischa HOURS=$(echo "0.${DAYS##*.} * 24" | bc -l)
26 6154cf32 2019-03-12 mischa MINUTES=$(echo "0.${HOURS##*.} * 60" | bc -l)
27 6154cf32 2019-03-12 mischa SECS=$(echo "0.${MINUTES##*.} * 60" | bc -l)
28 86ad8e4b 2019-05-04 mischa test -n "${DAYS%.*}" && printf '%s days, ' "${DAYS%.*}" > ${UPTIMEINFO}
29 6154cf32 2019-03-12 mischa printf '%02d\\:%02d\\:%02d\n' "${HOURS%.*}" "${MINUTES%.*}" "${SECS%.*}" >> ${UPTIMEINFO}