Random script error with rndc

Hello coders,

been running into an strange behavior into one of my script and i'm wondering if my code wouldn't be responsible.

Bash on rhel 5.7

This is a basic check to see if bind is up and running on server.

# rndc check
INFO="Checking rndc"
for DNS_SERVER in ${DNS_MASTER_SERVERS[@]}; do
        check_rndc_status || { error_log "NAMED server is not running on ${DNS_SERVER}.  Please check servers"; exit 1; }
done

The function that does the actual checking

check_rndc_status () {
        rndc -k ${RNDC_KEY} -s ${DNS_SERVER} status > /dev/null 2>&1
        return $?
}

This code works BUT sometimes it gives me an error. Can't pinpoint an actual cause. But this is what i can say:

1- Never fails if i launch the script manually
2- Autosys launches a script that launches the Restart Script (sometimes good/sometimes bad)
3- Same thing sometimes happends when another script calls the Restart Script
4- Bind is always up and running never restarted/fail/overcapacity

If anybody has an idea or see's an error in my code that could create the error i'm all ears. Thanks.

Sometimes gives you what error? Knowing that'd be helpful.

Double-check that the contents of ${DNS_MASTER_SERVERS[@]} are always what you want. There could be something wonky ending up in there like a blank line or something.

I think the return $? is redundant, it'd be doing that anyway.

Thanks for your answer.

It gives me 1 meaning the rndc command didn't return 0 and the script exits.

But like i said the command always works manually so meaning (i think) that the problem lies with my script and not with the rndc command.

Yeah your right about the return.... that's a residu from another fonction so i'll remove it.

I'll check the array.... i think you may be right.... great trail but it bafles me that it always work when i do it manually and that sometimes (not always) it fails when a script call my script.

If rndc is completely unable to give you any information except the return code, you may need to start printing statements into a file for you to read later.

You mean something like this?

rndc -k ${RNDC_KEY} -s ${DNS_SERVER} status > $some_temp_file 2>&1
tail -1 | grep up $some_temp_file

Probably something more like:

rndc -k ${RNDC_KEY} -s ${DNS_SERVER} status > $some_temp_file 2>&1
tail -1 $some_temp_file | grep up

or:

rndc -k ${RNDC_KEY} -s ${DNS_SERVER} status > $some_temp_file 2>&1
tail -f $some_temp_file | grep up

Oh my .... need more coffee.... Thanks Don.

Is it standard to redirect outputs into a file and then looking into that file to pull out the information you wanted? In my case it looks like alot of i/o's and external commands JUST to get the return of one command.

I hate random errors.... at least when it's broken you know it doesn't work... now it works but sometimes it fails.... grrrrr.

It would seem that:

tail -1 log | grep up

could be discarding diagnostics indicating why rndc failed. Is there some reason why something like:

rndc -k ${RNDC_KEY} -s ${DNS_SERVER} status > $some_temp_file 2>&1 || cat $some_temp_file

wouldn't give you a better indication of what might have gone wrong? Or, if you don't want to see normal output, but want to see diagnostic output, have you considered something simpler, like:

rndc -k ${RNDC_KEY} -s ${DNS_SERVER} status > /dev/null

(which is not redirecting standard error at all).

Problem is that its a parent script that launches this one so we don't get to see standard output or standard error on the term. That way the temp file would really help. Each time i try to run it myself it is always succefull.

I even tried this to see if it was not a rndc overload problem

for (( x=1; x<=500; x++ )); do rndc -k <key> -s <serverip> status| grep up; echo $?; done

And not a single fault.

Maybe i could put my check in a loop saying well if it fails the first time maybe try again in like 2-3 seconds? I'm the first one to scream at people using sleep in their script but maybe it's time i revise my position :smiley:

Eh, it's like log files. If you don't know what you're looking for, you don't know what's safe to throw away. At least this is temporary...

I get it.... i've modified the rndc to keep the important stuff. Of course it makes sense.

Will let you guys know what i can find out. Thanks again.