-
-
Save gebn/1a93ea06f6f2ed2c4438 to your computer and use it in GitHub Desktop.
Finds and connects to a UG04 lab machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# will hold available machine hostnames | |
alive=() | |
# iterate through a subset of machines in UG04 | |
for suffix in {10..100}; do | |
# ping each one | |
ping -c 1 -t 1 "cca-ug04-130$suffix" > /dev/null 2>&1 | |
# if the ping command succeeded, the machine is available | |
if [ $? -eq 0 ]; then | |
# add it to the list | |
alive+=("cca-ug04-130$suffix") | |
fi | |
done | |
# count the number of available machines | |
count=${#alive[@]} | |
echo "Found $count machines." | |
# pick a machine from the list at random | |
theChosenOne=${alive[$((RANDOM % $count))]} | |
# connect to it, accepting any unseen host key | |
echo "Connecting to $theChosenOne..." | |
ssh -o StrictHostKeyChecking=no "$theChosenOne" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment