Quand on travaille chez un hébergeur, le DNS fait probablement partie des services sur lesquels on intervient chaque semaine. Ce script permet de mettre à jour automatiquement un ou plusieurs fichiers de zone DNS. Pour le numéro de série, laissez simplement Bash le faire pour vous.
Comme on travaille rarement seul chez un hébergeur, il faut vérifier que personne d’autre n’utilise le script en même temps. Il faut aussi pouvoir suivre les modifications : elles sont donc toutes archivées.
PS : n’oubliez pas d’installer gawk sur votre serveur avant !
Maintenant, place au shell. Il suffit de le lancer comme ça :
./sdu.sh /var/lib/named/master/myzone.com.hosts ou
ls /var/lib/master/*.hosts |xargs -l ./sdu.sh for a massive updateVous pouvez aussi utiliser une liste de domaines :
cat zonelist.txt |xargs -l ./sdu.sh[code]
<strong>You can also put it directly in your path</strong>
<span style="text-decoration: underline;"><strong>The script :</strong></span>
[code]
#!/bin/sh
# Serial DNS Updater by Christophe Casalegno (Brain 0verride)
# christophe.casalegno@digital-network.net
tmpdir="/tmp"
backupdir="/backupdns"
dirlock="/var/run"
datename=`date +"%d-%m-%y-%T"`
zonefile=$1
SCRIPTNAME=`basename $0`
# First verification, process already launched ?
export LOCKSYNC="$dirlock/$SCRIPTNAME.lock"
PID=$$
echo "["`date +"%Y/%m/%d %H:%M:%S"`"] Trying to launch script $0"
if [ -f "$LOCKSYNC" ]
then
echo "Wait : lockfile "$LOCKSYNC" is present. we must verify..."
PIDLOCK=`cat $LOCKSYNC`
if [ -f /proc/$PIDLOCK/exe ]
then
echo "The process is currently running. Launching $SCRIPTNAME aborted."
exit
else
echo "The process doesn't seems currently running anymore. Lauching $SCRIPTNAME"...
rm $LOCKSYNC
fi
fi
echo "Lockingfile creation... "$LOCKSYNC
echo $PID > $LOCKSYNC
# Second verification : backupdir exist ?
if [ -r "$backupdir" ]
then
echo "The backup directory already exist : it's cool, don't worry"
echo "Processing..."
else
echo "The backup directory doesn't exist : Creating backup directory..."
mkdir $backupdir
fixdate=$datename
mkdir $backupdir/$fixdate
fi
cat $zonefile > $backupdir/$fixdate/$zonefile
gawk 'BEGIN{ser=strftime("%Y%m%d",systime() )*100} /[0-9]{9,10}/{sub($1,$1 < ser ? ser : $1+1)}1' "$zonefile" > $tmpdir/$zonefile.tmp
cat $tmpdir/$zonefile.tmp > $zonefile
rm $tmpdir/$zonefile.tmp
Vous pouvez aussi télécharger le script ici : sdu.sh
Christophe Casalegno
Vous pouvez me suivre sur : Twitter | Facebook | Linkedin | Telegram | Youtube

Laisser un commentaire
Ajouter un commentaire