-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsnewserial.sh
45 lines (36 loc) · 987 Bytes
/
dnsnewserial.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
# Change DNS zone serial in YYYYMMDDNN format
# v.20180401 (c)2016-18 by Max Kostikov http://kostikov.co e-mail: [email protected]
#
# Usage: dnsnewserial.sh /path/to/zone/file
#
# Check arguments
if [ $# -ne 1 ]
then
echo "Provide /mnt/docker/nsd/zones/db.domaine.com as argument!" # modifier avec votre fichier de zone
exit 1
fi
# is zone file exist?
if [ ! -f $1 ]
then
echo "Zone file $1 not found!"
exit 1
fi
# get current serial
curser=`cat $1 | awk -v RS='@' '$1 == "IN" && $2 == "SOA" { print $6 }'`
if [ -z "$curser" ]
then
echo "Serial not found in $1 file!"
exit 1
fi
newser=`date '+%Y%m%d'`
if [ `expr $curser : $newser` = 8 ] # if serial today was already changed
then
newser=`expr $curser + 1` # increment it
else
newser=${newser}00 # else assign new
fi
# write new serial to zone file
sed -i.bak "s/$curser/$newser/" $1
# print new serial as confirmation
echo $newser