#! /bin/sh -x # -*- sh -*- # $Header$ # $Log$ # This script runs as user root, so that it has permission to overwrite # /etc/dhcpd.conf and also to restart the dhcp server. HOME="/root" MNT_DIR="/var/ipsetup" # MNT_CMD="${HOME}/bin/mountexcel" # UMOUNT="/bin/umount" TMP_DIR="${HOME}/tmp" MAKE_DHCP="/root/bin/make-dhcpd-conf" MAKE_DNS="/root/bin/make-dns-db" PATH=$PATH:/usr/local/bin:/root/bin DNSDIR=/var/named # if mount | grep ipsetup >& /dev/null # then # set ${MNT_DIR}/*.txt # if [ ! -f $1 ] # then # ${UMOUNT} ${MNT_DIR} >& /dev/null # ${MNT_CMD} # fi # else # ${MNT_CMD} # fi # set ${MNT_DIR}/*.txt # if [ ! -f $1 ] # then # echo "${MNT_DIR} seems to be mounted, but no file *.txt!" # exit 3 # fi # If the Excel spreadheet file or the text hosts file we've been using # is newer than the configuration file, then # rebuild configuration. EXCEL_FILE=${MNT_DIR}/ict-mac-ip-address-computer-list.xls ORIG_HF=${DNSDIR}/hosts/hosts HOSTFILE=${DNSDIR}/hosts/ict-mac-ip-address-computer-list-text.txt for file in $EXCEL_FILE $ORIG_HF do if [ "$file" -nt "/etc/dhcpd.conf" ] then parse-excel.pl $EXCEL_FILE > $HOSTFILE cat $ORIG_HF >> $HOSTFILE if ${MAKE_DHCP} $HOSTFILE > ${TMP_DIR}/dhcpd.conf then echo "/bin/cp -a ${TMP_DIR}/dhcpd.conf /etc/dhcpd.conf" /bin/cp -a ${TMP_DIR}/dhcpd.conf /etc/dhcpd.conf /etc/rc.d/init.d/dhcpd restart # If the clock on the Windows PC that was used to edit the # spreadsheet is set earlier than on this machine, we have a # problem where this script continuously updates and restarts # the servers every two minutes until the condition that the # excel file is newer than the dhcpd.conf file is false. # By making them both the same date, we avoid that problem. # Actually, to really solve it, we need to make dhcpd.conf # have a timestamp >= that of newest text file, not the first one. # But as we say in Australia, it's "rough enough for the bush". if [ "$file" -nt "/etc/dhcpd.conf" ] then touch --reference=$file "/etc/dhcpd.conf" fi cd $DNSDIR service named stop sleep 5 ${MAKE_DNS} $HOSTFILE rm *.jnl service named start exit 0 fi fi done