Skip to content

Commit 35d5680

Browse files
committed
fix for #34
better error checking for DHCPD files Apparently DSM 7 may not always have a dhcpd-leases.log file
1 parent cb796db commit 35d5680

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

poll-dhcp-changes.sh

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
#!/bin/sh
22

3-
while true; do
4-
ATIME=`stat /etc/dhcpd/dhcpd-leases.log | grep Modify`
5-
6-
if [[ "$ATIME" != "$LTIME" ]]; then
7-
date
8-
echo "dhcp leases changed - reloading DNS"
9-
/var/services/homes/admin/diskstation_dns_modify.sh
10-
LTIME=$ATIME
11-
fi
12-
sleep 5
3+
while true; do
4+
reload_dns=false
5+
if [ -r /etc/dhcpd/dhcpd-leases.log ]; then
6+
LOGATIME=`stat /etc/dhcpd/dhcpd-leases.log | grep Modify`
7+
if [ "$LOGATIME" != "$LOGLASTATIME" ]; then
8+
date
9+
LOGLASTATIME=$LOGATIME
10+
reload_dns=true
11+
fi
12+
elif [ -r /etc/dhcpd/dhcpd.conf.leases ]; then
13+
LEASEATIME=`stat /etc/dhcpd/dhcpd.conf.leases | grep Modify`
14+
if [ "$LEASEATIME" != "$LEASELASTATIME" ]; then
15+
date
16+
LEASELASTATIME=$LEASEATIME
17+
reload_dns=true
18+
fi
19+
else
20+
echo "ERROR - No dhcp lease files found. Is something misconfigured?"
21+
exit 1
22+
fi
23+
if "$reload_dns"; then
24+
echo "dhcp leases changed - reloading DNS"
25+
/var/services/homes/admin/diskstation_dns_modify.sh
26+
fi
27+
sleep 5
1328
done
1429

1530

0 commit comments

Comments
 (0)