#!/bin/sh
                                                                                               
MASTER=Your Plesk Hosting
USER=Site User Name 
PASS=Site Password
FILE=secondaries.include
FILE_P=/etc/bind/

                                                                                               
if [ -f $FILE_P$FILE.tmp ] ; then
  rm -f $FILE_P$FILE.tmp
fi
wget http://$MASTER/$FILE --http-user=$USER --http-password=$PASS -O $FILE_P$FILE.tmp >/dev/null 2>&1
                                                                                               

if [ -f $FILE_P$FILE.tmp ]; then
  SIZE=`stat $FILE_P$FILE.tmp |grep Size |awk '{print $2}'`
else
  echo "Error: $FILE_P$FILE.tmp not detected"
  exit 1
fi

                                                                                               
if [ $SIZE = 0 ]; then
  echo "ERROR! The secondary file is 0 length!"
  exit 1
else
  if [ -f $FILE_P$FILE.tmp ]; then
    if `/usr/bin/diff -q  $FILE_P$FILE.tmp $FILE_P$FILE>/dev/null 2>&1`; then
     rm -f $FILE_P$FILE.tmp
    else
     mv $FILE_P$FILE.tmp $FILE_P$FILE
     chmod 644 $FILE_P$FILE
     /usr/sbin/rndc reload >/dev/null 2>&1   
    fi
  fi
fi

