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
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.
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.
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.
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
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