Skip to content

Instantly share code, notes, and snippets.

@bartvdbraak
Created June 6, 2023 14:30
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 bartvdbraak/24a09bc4cb1dd2053a12c107a2f359e6 to your computer and use it in GitHub Desktop.
Save bartvdbraak/24a09bc4cb1dd2053a12c107a2f359e6 to your computer and use it in GitHub Desktop.
This script can be used to check a list of domains against a desired outcome by utilizing the `dig` command. It provides information on whether each domain matches or mismatches the expected outcome.
#!/bin/bash
print_help() {
echo "Usage: ./domain_check.sh DESIRED_OUTCOME DOMAIN1 [DOMAIN2 ...]"
echo "Check a list of domains against a desired outcome using the dig command."
echo ""
echo "Arguments:"
echo " DESIRED_OUTCOME The expected outcome for the domains."
echo " DOMAIN1 The first domain to check."
echo " DOMAIN2 ... Additional domains to check."
echo ""
echo "Example:"
echo " ./domain_check.sh SPECIFIC_OUTCOME example.com example.org example.net"
}
desired_outcome="$1" # Desired outcome provided as the first command-line argument
domain_list=("${@:2}") # Domain list provided as command-line arguments starting from the second argument
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
print_help
exit 0
fi
if [ -z "$desired_outcome" ] || [ ${#domain_list[@]} -eq 0 ]; then
echo "Error: Insufficient arguments."
echo ""
print_help
exit 1
fi
echo "Checking domains against the desired outcome: $desired_outcome"
echo ""
for domain in "${domain_list[@]}"; do
result=$(dig +short "$domain")
if [[ "$result" != "$desired_outcome" ]]; then
echo "Domain: $domain"
echo "Expected Outcome: $desired_outcome"
echo "Actual Outcome: $result"
echo "Status: Mismatch"
echo ""
else
echo "Domain: $domain"
echo "Expected Outcome: $desired_outcome"
echo "Actual Outcome: $result"
echo "Status: Match"
echo ""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment