Skip to content

Instantly share code, notes, and snippets.

@Aricg
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save Aricg/11405434 to your computer and use it in GitHub Desktop.

Select an option

Save Aricg/11405434 to your computer and use it in GitHub Desktop.
querydns and autocomplete on a dumped zone file
#!/bin/bash
# BEGIN CRON DAILY ##
bind_server=foo.bar.com
if ssh root@$bind_server 'rndc dumpdb -zones'
then
scp -q root@$bind_server:/var/cache/bind/named_dump.db /tmp/
grep -v '^;' /tmp/named_dump.db|awk {'print $1'}|grep -v 'IN-ADDR'|sed s/\.$//|tr '[A-Z]' '[a-z]'|egrep -v '^[1-9]'|egrep -v '^\*'|sort|uniq > ~/.ssh_hosts
awk '{print $1" <--> "$5}' /tmp/named_dump.db | grep -vE '(nse|;|ARPA)' | tr '[A-Z]' '[a-z]'|sed -e 's/. / /' -e 's/ -/ /' -e 's/\.$//' > ~/.ssh_hosts_ips
fi
#### END CRON DAILY
#querydns completion
# in .profile or .bashrc
if [ -e ~/.ssh_hosts ]; then
complete -W "$(cat ~/.ssh_hosts)" s ssh rsync querydns
fi
##
##### END .bashrc
#Regular querydns command (I guess you could just make this an alias if you dont need the command completion above.
## make executable /opt/local/bin/querydns
grep -i < ~/.ssh_hosts_ips "$@"
##### END /opt/local/bin/querydns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment