Skip to content

Instantly share code, notes, and snippets.

@W-A-James
Created June 22, 2023 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W-A-James/88d04ed5a955acfa06d690ef02d0e4e1 to your computer and use it in GitHub Desktop.
Save W-A-James/88d04ed5a955acfa06d690ef02d0e4e1 to your computer and use it in GitHub Desktop.
Get host name of named evergreen host
#!/bin/bash
# provide evergreen host name as only argument
# Returns <user>@<hostname> for the specified host and fails if no host is found
USAGE=$(cat << EOM
$0 <name>
EOM
)
NAME=$1
if [ -z $NAME ]; then
echo 'Must provide name of evergreen host'
echo
echo $USAGE
exit 1
fi
SCRIPT=$(cat << EOM
# Check for host with name that matches argument
/Name: $1;/!d
# Extract host user and hostname
s/^.*Host name: (.*);(.*)User: (.*)\;.*\$/\3@\1/
p
EOM
)
user_host_string=$(evergreen host list | sed --regexp-extended --quiet -e "${SCRIPT}")
if [ -z $user_host_string ]; then
echo "No host with name '${NAME}' found"
exit 1
fi
echo $user_host_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment