dmccabe
September 29, 2015, 9:49am
1
Hi,
I am testing some code to match a grep to see if one of the dns server exists but it does not seem to match:
ERROR:
CRITICAL: google.com DNS : ns3.google.com NOT found
CODE:
if [`dig +short NS google.com | grep ns3.google.com| wc -l` -eq 1 ]; then
echo "OK: google.com DNS : ns3.google.com exists"
else
echo "CRITICAL: google.com DNS : ns3.google.com NOT found"
fi
COMMAND:
dig +short NS google.com
OUTPUT:
ns3.google.com .
ns2.google.com .
ns4.google.com .
ns1.google.com .
Thanks,
sea
September 29, 2015, 10:37am
2
Heya
For some reason this machine has no dig available, so the following is untesteted.
Try:
SEARCH="ns3.google.com"
RESULT=$(dig +short NS google.com | grep "$SEARCH")
[ "$SEARCH" = "$RESULT" ] && \
echo "OK: google.com DNS : ns3.google.com exists" || \
echo "CRITICAL: google.com DNS : ns3.google.com NOT found"
hth
cero
September 29, 2015, 10:37am
3
@dmccabe : Your script thorws a different error message than you describe: [1: command not found
This is because there is no space after the square bracket:
if [ `dig +short NS google.com | grep ns3.google.com| wc -l` -eq 1 ]; then
Aia
September 29, 2015, 11:40am
5
The condition could be done as just:
$ if [[ -n $(dig ns3.google.com +short) ]] ; then ... fi