Skip to content

Instantly share code, notes, and snippets.

@mrunkel
Created August 2, 2017 20:27
Show Gist options
  • Save mrunkel/f75622c06c135a18fe47b9febe7721c9 to your computer and use it in GitHub Desktop.
Save mrunkel/f75622c06c135a18fe47b9febe7721c9 to your computer and use it in GitHub Desktop.
simple bash shell script adds an A record and a PTR for the passed fqdn/ip pair
#!/bin/bash
# adds an A record and a PTR for the passed fqdn/ip pair
function printUsage () {
echo "usage: $0 fqdn ip"
echo
}
if [ $# -ne 2 ] ; then
printUsage
exit 1
fi
cli53="/usr/local/bin/cli53"
if [ ! -x $CLI53 ] ; then
echo "cli53 not installed."
echo "google is your friend."
exit 1
fi
fqdn=$1
ip=$2
hostname=`expr "$fqdn" : '\([^.][^.]*\)\..*'`
domain=`expr "$fqdn" : '[^.][^.]*\.\(.*\)'`
echo "Hostname: $hostname"
echo "Domain: $domain"
IFS=. read ip1 ip2 ip3 ip4 <<< "$ip"
echo "IP: $ip1 $ip2 $ip3 $ip4"
ptrdomain="$ip3.$ip2.$ip1.in-addr.arpa."
echo "Creating A record"
$cli53 rrcreate --wait -x 300 $domain $hostname A $ip
echo "Creating PTR"
$cli53 rrcreate --wait -x 300 $ptrdomain $ip4 PTR $fqdn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment