Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- #
- # Created by Gilad Halevy 5/3/11 to check MX records
- # Check for command line arguments, otherwise set domain list statically
- if [[ "$#" != "0" ]]; then
- domains="$@"
- else
- domains=("2kgames.com" "2ksports.com" "take2international.com" "vcentertainment.com" "2kaustralia.com" "2kaustralia.com.au" "irrational.com.au" "irrationalgames.com" "irrationalgames.com.au" "2kboston.com" "2klosangeles.com" "kushgames.com" "beaterator.com" "rockfoo.com" "rockstar.com" "rockstarlondon.com" "globalstarsoftware.com" "rockstargames.com" "rockstarleeds.com" "rockstartoronto.com" "rockstarvancouver.com" "take2games.com" "irrationalstudios.com" "2kmarin.com" "libertycitypolice.com" "rockstarnewengland.com" "maddocsoftware.com" "firaxis.com" "rockstarlincoln.com" "take2espana.com" "take2europe.com" "rockstarsd.com" "rockstarsandiego.com" "take2asia.com" "catdaddy.com" "catdaddygames.com" "powerstationrecall.com" "taketwo.fr joagcanada.com" "irrationalboston.com" "jackofallgames.com" "take2.de" "gouranga.com" "take2interactive.com.au" "2kgames.com.au" "2ksports.com.au" "take2benelux.com" "2kczech.com" "2kczech.cz" "illusionsoftworks.com" "illusionsoftworks.cz" "illusionsoftworks.eu" "is.cz" "mafia-game.com" "mafia-game.cz" "rockstarnorth.com" "rockstarnorth.co.uk" "2k.com" "take2.it" "2kchina.com" "2kgames.cn")
- fi
- ERRORFILE=/tmp/mxcheck_errors
- if [[ -f "$ERRORFILE" ]]; then
- rm "$ERRORFILE"
- fi
- # set variables
- setvars () {
- mx="$(dig "$domain" MX | grep -s -e "$domain" -e MX | tail -2 | sort -k3n)" # get just the MX records, place them in a var
- mx1="$(echo "$mx" | head -1 | awk '{ printf ("%-25s%-15s%-15s%-25s", $1, $2, $5, $6) }')" # print fancy fields for mx1
- mx2="$(echo "$mx" | tail -1 | awk '{ printf ("%-25s%-15s%-15s%-25s", $1, $2, $5, $6) }')" # print fancy fields for mx2
- mx1Aip="$(dig $(echo "$mx1" | awk '{ print $4 }') A +short)" # dig for the IP for mx1
- mx2Aip="$(dig $(echo "$mx2" | awk '{ print $4 }') A +short)" # dig for the IP for mx2
- }
- for domain in ${domains[@]}; do
- setvars # call setvars
- if [[ "$mx2" =~ ^"$domain" ]]; then # Check via regex if MX records exist
- printf "%-25s%-15s%-15s%-25s%-20s\n" "DOMAIN" "TTL" "PRIORITY" "RECORD" "IP"
- printf "%-25s%-15s%-15s%-25s%-20s\n" "------" "---" "--------" "------" "--"
- echo -e "$mx1""$mx1Aip"
- echo -e "$mx2""$mx2Aip\n"
- else # records do not exist
- echo "WARNING - MISSING MX RECORDS FOR DOMAIN ${domain}!" 1>>"$ERRORFILE" # output errors to tmp file
- fi
- done
- # Print errors
- if [[ -s $ERRORFILE ]]; then
- cat "$ERRORFILE" && rm "$ERRORFILE" # print contents of error file to STDOUT, then discard it
- fi
- exit
Advertisement
Add Comment
Please, Sign In to add comment