The objective is simple, a periodic cron cache dump of powerdns recursor on a setup.
1. create a shell code as below using nano-
#nano /usr/local/bin/pdns-cache-dump.sh
#!/bin/sh
DAY=`/bin/date +%Y%m%d`
TFILE="/var/log/pdns-cache/$(basename $0).$DAY.csv"
rec_control dump-cache $TFILE
echo "cache dump completed, dump script by rumi (hasan.emdad@mango.com.bd)"
#chmod 0777 /usr/local/bin/pdns-cache-dump.sh
2. create directory to store the dump files
#mkdir /var/log/pdns-cache
#chown -R pdns-recursor /var/log/pdns-cache
3. Add it to CRON (you can use webmin for this)
Go to Webmin's System > Schedule CRON Jobs > Create a new scheduled CRON job and add-
Execute CRON as- root
Active- Yes
Command- /usr/local/bin/pdns-cache-dump.sh
When to execute- Simple Schedule (Daily at midnight)
Leave other parts as default
"Save"
It's done 🙂