Score:0

rndc flushname works from command line, but not from bash script

cn flag
Zak

I am banging my head against the wall here trying to figure this out. I have an automated DNS propagation system I am trying to build internally, and everything works except rndc flushname. If I do this at a shell prompt

$ sudo rndc flushname /var/lib/bind/$domain.hosts
$ sudo rndc reload

This works

Also if I create the following bash script:

#!/bin/bash
domain="some-domain.com"
# Do stuff 
rndc flushname /var/lib/bind/$domain.hosts
rndc reload

And run it

$ sudo bash myScript.sh

It works.

This command is not working if I assign the script to a cron job though IE

$ sudo crontab -e

 .... 
 ....

 */5 * * * * bash /etc/bind/dnsCron/dnsCron.sh

Why does rndc work from straight shell. It also works manually called in a bash script. But when called from crontab it doesn't reload? All commands are run through sudo and the crontab is also running under root. I am not sure what the issue is here? Is there another method to call rndc flushname ?

hr flag
You can redirect the output of your cron command to a file, and check it for errors. My guess would be that `rndc` is in /usr/sbin, and that is not in cron's (very minimal) PATH
Zak avatar
cn flag
Zak
OK I have changed it to full path --> `/usr/sbin/rndc flushname /var/lib/bind/$domain.hosts` -- Also keeping an eye on `/var/mail/root` as all my cron jobs output there. I will report back after cron runs this next time ..
Zak avatar
cn flag
Zak
I feel stupid. I should have known better! Post this an an answer and I'll accept unless you can find this as a duplicated OP .. But I did search it out, I promise!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.