-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbind-refresh-all_public.sh
48 lines (30 loc) · 1.24 KB
/
bind-refresh-all_public.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
46
47
48
#!/bin/bash
date +%Y%m%d%H > date.txt
file=db.file
bottomserial=$(cat $file | grep Serial | awk '{print $1}')
topserial=$(cat $file | grep last | awk '{print $6}')
timestamp=$(cat date.txt)
temp=$bottomserialplusone
if [[ $bottomserial = $timestamp ]] && [[ $topserial = $bottomserial ]]; then
echo "Serials are the same, adding 1 to the bottom serial"
bottomserialplusone=$(awk "BEGIN {print $bottomserial + 1}")
sed -i "10s/$bottomserial/$bottomserialplusone/g" "$file"
else
cp $file backup/.
echo "Copying actual serial into old one"
sed -i "s/$topserial/$bottomserial/g" "$file"
echo "Updating new serial"
sed -i "10s/$bottomserial/$timestamp/" "$file"
echo "Serials were udpated for $file"
fi
refreshbind="/usr/local/sbin/bind-refresh.sh"
restartbind="systemctl restart bind9"
echo "Restarting Bind9 in dns1"
$restartbind && sleep 2 && systemctl status bind9 |grep ago
if [[ $(dig @localhost domain.com. |grep ANSWER: |awk '{print $10}' | cut -f1 -d ",") = "1" ]]; then
echo "Restarting Bind9 in dns3"
ssh dns3 "$refreshbind && sleep 2 && systemctl status bind9 |grep ago"
echo "Restarting Bind9 in dns4"
ssh dns4 "$refreshbind && sleep 2 && systemctl status bind9 |grep ago"
echo "Script terminated, if errors please look out"
fi