Skip to content

Instantly share code, notes, and snippets.

@tlesh989
Last active March 16, 2022 16:49
Show Gist options
  • Save tlesh989/f06478c6c17580b476fc30eccb20df73 to your computer and use it in GitHub Desktop.
Save tlesh989/f06478c6c17580b476fc30eccb20df73 to your computer and use it in GitHub Desktop.
script to test connectivity to all nodes in a mongodb cluster
#!/usr/bin/env bash
readarray -t mongo_cluster <<< "$(dig +short srv _mongodb._tcp.example.com | awk '{print $4}')"
function ping_cluster() {
a=("$@")
for i in "${a[@]}"
do
nc -w 3 -z -v "$i" 27017
done
}
ping_cluster "${mongo_cluster[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment