Board index Linux Shell Scripts

Moderator: chandranjoy

DNS Zone Converter Script

Postby chandranjoy » Wed Apr 19, 2017 1:01 pm

Code: Select all
#!/bin/bash
## By Jay
## VARS
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
DATE=`/bin/date +%Y-%m-%d`
TARGET_FOLDER="/var/backups/dns01"
LOG="/var/log/dns_zone_conv.log"

## CHECK ZONE FILE TYPE RAW OR TEXT
if [ -f $TARGET_FOLDER/$DATE/domain.com.zone ];
then
# File Check
FC=`file $TARGET_FOLDER/$DATE/domain.com.zone|(cut -d: -f2)`
else
echo "ERROR: domain.com.zone not exists" >> $LOG
echo "Using domain1.com zone instead of that." >> $LOG
FC=`file $TARGET_FOLDER/$DATE/domain1.zone|(cut -d: -f2)`
fi

RAW_TEXT() {
## Convert DNS raw zone files into text
#echo > $LOG
echo `date` >> $LOG
echo "--------------------------------" >> $LOG
#echo "" >> $LOG
cd $TARGET_FOLDER/$DATE
for i in $(ls|sed 's/.\zone//g');
do named-compilezone -f raw -F text -o $i.zone $i $i.zone;
echo $i.zone converted as text >> $LOG;
done
echo "--------------------------------" >> $LOG
echo "RAW to TEXT conversion done on `date` - $TARGET_FOLDER" >> $LOG
}

TEXT_RAW() {
## Convert DNS text zone files into raw
echo > $LOG
echo `date` >> $LOG
echo "-------------------------------" >> $LOG
#echo "" >> $LOG
cd $TARGET_FOLDER/$DATE
for i in $(ls|sed 's/.\zone//g');
do named-compilezone -f text -F raw -o $i.zone $i $i.zone;
echo $i.zone converted as raw >> $LOG;
done
echo "--------------------------------" >> $LOG
echo "TEXT to RAW conversion done on `date` - $TARGET_FOLDER/$DATE" >> $LOG
}

## Call Function, based-on File detection
if [ "$FC" == " data" ];
then
RAW_TEXT;
else
TEXT_RAW;
fi
chandranjoy
Site Admin
 
Posts: 283
Joined: Fri Oct 23, 2009 11:19 pm

Return to Shell Scripts

Who is online

Users browsing this forum: No registered users and 1 guest


cron