wagon/back/lib/ns_lookup_send

28 lines
659 B
Bash
Executable File

#!/bin/bash
# FILE: wgapi:back/lib/ns/lookup/send
# DESCRIPTION: Send nslookup command to DNS master server
# USAGE: send cmd
# ERRORS:
# 3: bad usage
# 4: not found
# 5: server down
# 6: nslookup not found
# 7: config file not found
# 8: other nslookup error
CONFIG_FILE='/etc/wgapi/config'
[ ${#} -eq 1 ] || exit 3
[ -f "${CONFIG_FILE}" ] || exit 7
[ -x /usr/bin/nslookup ] || exit 6
source "${CONFIG_FILE}"
if ! res="$(/usr/bin/nslookup "${1}" "${DNS_MASTER}")"
then exit 8
fi
if <<<"${res}" grep ';; .* timed out'
then exit 5
elif <<<"${res}" grep "\*\* .*: NXDOMAIN\|\*\*\* .*: No answer"
then exit 4
else printf '%s' "${res}"
fi