Scripts - Add - DNS Record
What : This script is going to add the CNAME record map to srv001, and add under the record srv001
HowTo : ./add-cname-record.sh recordname
Create a file name: add-cname-record.sh and the following content:
#!/bin/bash
USAGE="Usage: $0 recordname"
if (! test $1)
then
echo $USAGE
exit 1
fi
echo "Checking is the domain: $1.vannakk.net existed or not yet."
FILE=/etc/bind/forward.vannakk.net.zone
grep -w "$1" $FILE >/dev/null
if [ $? -eq 0 ]
then
echo "Domain: $1.vannakk.net already existed "
exit 1
else
echo "Domain: $1.vannakk.net not yet existed. So this domain will be add."
sed -i '/^srv001/a \'$1' IN CNAME srv001.vannakk.net.' $FILE
fi
echo "Updating Serial..."
SERIAL=$(awk '/serial/{print $1}' $FILE)
sed -i "/serial/s/$SERIAL/$(expr $SERIAL + 1)/" $FILE
echo "Reloading service named"
service bind9 reload
echo "Domain: $1.vannakk.net is added."
No comments:
Post a Comment