Skip to content

Instantly share code, notes, and snippets.

@robobenklein
Last active October 27, 2017 14:52
Show Gist options
  • Save robobenklein/0c4cb653234f36adbc4ea6aa425beec5 to your computer and use it in GitHub Desktop.
Save robobenklein/0c4cb653234f36adbc4ea6aa425beec5 to your computer and use it in GitHub Desktop.
Who's on hydra?
Host hydra*
Hostname %h.eecs.utk.edu
User <netid>
ForwardX11 yes
forwardagent no
# note: dis is expanding using ZSH
# if you don't have the timeout command, just remove `timeout 2s ` from the command
# you should have yer ssh key set up
for i in {0..30};do timeout 2s ssh hydra${i} -o ConnectTimeout=1 -o ConnectionAttempts=1 -o PasswordAuthentication=no users | xargs echo users on hydra${i}: ;done
#!/bin/bash
TMPDIR=/tmp/hydrausers
TIMEOUT=10
DEBUGLOG=${TMPDIR}/debug.log
FAILURE=0
mkdir -p $TMPDIR
touch $DEBUGLOG
declare -g -A failures
declare -g -A hydrausers
ssh hydra0 echo
hydralist=$(echo hydra{0..30})
# get all whos and put them into /tmp/hydrausers
function gethydras() {
rm /tmp/hydrausers/hydra* 2>&1 >/dev/null
parallel-ssh -i -t $TIMEOUT -o /tmp/hydrausers -H "${hydralist}" \
'users' > $DEBUGLOG
FAILURE+=$(grep 'FAILURE' $DEBUGLOG | wc -l)
while read -r failedhost; do
# skip nothing, literally
if [[ $failedhost == "" ]]; then continue; fi
echo '!FAILURE' > $TMPDIR/$failedhost
done <<< $(grep 'FAILURE' $DEBUGLOG | cut -d' ' -f4 )
# failures+=( ["$(grep 'FAILURE' $DEBUGLOG | cut -d' ' -f4)"]="$(grep 'FAILURE' $DEBUGLOG )" )
}
gethydras
for i in {0..30}; do
users=$(cat $TMPDIR/hydra$i )
if [[ $users == '!FAILURE' ]]; then
# rip
failures+=( ["hydra$i"]="$(cat $DEBUGLOG | grep hydra$i )" )
else
hydrausers+=( ["hydra$i"]="$(cat $TMPDIR/hydra$i )")
fi
done
for i in {0..30}; do
echo hydra$i: $(echo ${hydrausers[hydra$i]} | wc -w) users: ${hydrausers[hydra$i]}
done
for key in ${!failures[@]}; do
echo ${key} ${failures[${key}]}
done
# Total number of unique users:
cat /tmp/hydrausers/hydra* | grep -v '!FAIL' | tr ' ' '\n' | sort | uniq | wc -l | xargs echo 'total users:'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment