Bulk update TinyDNS

From V.S.V., Inc.
Jump to: navigation, search

If you use TinyDNS (and why wouldn’t you?), then you may have come across the following situation: the boss comes to you late on Friday and says I need 100 domain entries removed before the next update. What are you going to do? The entries are spread across dozens of files. It will take hours to do. Well, you can use a script like the one below. It was written by a colleague of mine by the name of Ted Carty. He is the guru of one-line scripts.

This script reads the list of URLs from a file, searches all your .data files for the matching lines and then expires those records.

for i in `cat ~/www_domain_site11.txt` ;
do k=`grep -E “^[C\+=]$i\.?:” /var/dnscache/*/*.data`;
if [ $? == 0 ];
then j=`echo $k|head -1 |cut -d: -f1`;
perl -ne “
chomp;
\$y=\$_;
if (m/^[C\+=]$i\.?:/) {
@x=split(‘:’,\$y);
\$x[2]=0;
\$x[3]=’400000004d03643c’;
\$z=join(‘:’,@x);
print \$z . \”:\n\”
} else {
print \$y . \”\n\”
}” $j;
fi ;
done

You will need to adjust the value of $x[3] to be the time of when you want the records to actually expire. You can easily get this value using the datemaker script.

This technique can be modified or combined with other scripts fairly easily to make changes to records also.

Note: Carriage returns have been added for readability. They don’t effect either the functionality or the one-linedness of the script.