Contents
- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases
Associated Information
- Unix Scripts Tips
Useful Links
-
Bash shell HOWTO
- Bourne Shell Man Page
-
C Shell Guide
- Korn Shell Resources
|
mx.sh
#!/usr/bin/ksh
#
# Script to report MX records for specific host
#
# Can be used to query other nameservers.
# Sorts MX records into priority order.
#
# Usage: mx hostname [ another DNS server ]
#
set -u
MYNAME=$(hostname)
TEMPFILE=/tmp/$MYNAME.$$
trap "rm $TEMPFILE > /dev/null 2>&1 " 0 1 2 3 15
PARMS=$#
if [ $# -lt 1 ]
then
echo
echo "Usage: $(basename $0) [alternate-nameserver]"
echo
exit 1
fi
HOSTNAME=$1
if [ $# -gt 1 ]
then
ALTDNS=$2
else
ALTDNS=""
fi
#
# This routine uses the rules for nslookup as defined in this
# machine, thus emulating what sendmail would do in this machine
# in following MX records. An alternate nameserver can also be
# specified.
#
echo
echo "Mail eXchange (MX) records for $1"
nslookup -type=mx $HOSTNAME $ALTDNS \
| grep "mail exchanger" \
| sort -n -k 4 > $TEMPFILE
if [ "$(cat $TEMPFILE | wc -l )" -gt "0" ]
then
cat $TEMPFILE | while read MXRECORD
do
echo $MXRECORD
done
else
echo
echo "No MX delivery records found for $1"
fi
shift
exit
rm $TEMPFILE > /dev/null 2>&1
#### END OF SCRIPT
|