Skip to content

Instantly share code, notes, and snippets.

@k-popov
Created December 24, 2013 15:53
Show Gist options
  • Save k-popov/8115023 to your computer and use it in GitHub Desktop.
Save k-popov/8115023 to your computer and use it in GitHub Desktop.
Tiny script that looks for CI nodes and outputs their uptime in minutes It's unable to cope with nodes running more than an day (separate output) and those which run less than hour (0 is printed)
#!/bin/bash
check_node() {
local ID="$1"
local NODE="$2"
UPTIME_LINE="$(ssh -q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null $NODE uptime < /dev/null)"
if echo "${UPTIME_LINE}" | grep -q 'days'; then
echo "${ID}:${NODE}:OLDERTHANADAY"
return 0
fi
TIME="`echo ${UPTIME_LINE} | grep -o -E '[0-9]{1,2}:[0-9]{1,2},' | tr -d ','`"
H="`echo ${TIME} | cut -f 1 -d :`"
M="`echo ${TIME} | cut -f 2 -d : | sed -e 's/^0*//'`" # cut 0 if it's frst in minutes value
test -z "$H" && H="0"
test -z "$M" && M="0"
MIN_TOTAL=$(( 10#$H * 60 + 10#$M ))
echo "${ID}:${NODE}:${MIN_TOTAL}"
return 0
}
lc-node-list | grep -F 'CI.' | while read GG_LINE; do
ID="`echo \"${GG_LINE}\" | cut -f 1`"
IP="`echo \"${GG_LINE}\" | cut -f 3`"
[[ "$ID" = "None" ]] && continue
check_node "${ID}" "${IP}"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment