Skip to content

Instantly share code, notes, and snippets.

@NQevxvEtg
Created July 22, 2026 22:46
Show Gist options
  • Select an option

  • Save NQevxvEtg/bf975375e6261df3023f94bc3c65df1d to your computer and use it in GitHub Desktop.

Select an option

Save NQevxvEtg/bf975375e6261df3023f94bc3c65df1d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <file> [rndc_key]"
echo " rndc_key defaults to /etc/rndc.key"
exit 1
fi
FILE="$1"
RNDC_KEY="${2:-/etc/rndc.key}"
if [[ ! -f "$FILE" ]]; then
echo "File not found: $FILE"
exit 1
fi
RNDC_OPTS=(-k "$RNDC_KEY")
# test rndc connectivity once
if ! rndc "${RNDC_OPTS[@]}" status &>/dev/null; then
echo "rndc connection failed — check key path or try without key arg"
exit 1
fi
while IFS= read -r line; do
name="${line#"${line%%[![:space:]]*}"}"
name="${name%"${name##*[![:space:]]}"}"
[[ -z "$name" || "$name" == \#* ]] && continue
printf "flushing: %s" "$name"
if rndc "${RNDC_OPTS[@]}" flushname "$name" &>/dev/null; then
printf " \033[32mOK\033[0m\n"
else
printf " \033[31mFAIL\033[0m\n"
fi
done < "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment