Bug #374 » rc.parse-isc-dhcpd.patch
rc.parse-isc-dhcpd.new 2010-02-25 13:42:06.000000000 -0500 | ||
---|---|---|
3 | 3 |
# This script will monitor dhcpd.leases and parse |
4 | 4 |
# out active leases and ensure they are present |
5 | 5 |
# in /var/etc/hosts |
6 |
SEARCH_DOMAIN=`grep ^domain /etc/resolv.conf | cut -f 2 -d ' '` |
|
6 | 7 | |
7 | 8 |
update_hosts_file() { |
8 | 9 |
# $1 = host |
9 | 10 |
# $2 = ip |
10 | 11 |
cat /var/etc/hosts | grep -v "$1" > /tmp/hosts.tmp |
11 | 12 |
if [ "$3" != "" ]; then |
12 |
echo "$2 $1 # dynamic entry created by rc.parse-isc-dhcpd" >> /tmp/hosts.tmp |
|
13 |
echo "$2 $1.$SEARCH_DOMAIN $1 # dynamic entry created by rc.parse-isc-dhcpd" >> /tmp/hosts.tmp
|
|
13 | 14 |
fi |
14 | 15 |
mv /tmp/hosts.tmp /var/etc/hosts |
15 | 16 |
killall -HUP dnsmasq |
16 | 17 |
} |
17 | 18 | |
18 | 19 |
# Parse file on initial run |
19 |
cat /var/dhcpd/var/db/dhcpd.leases | grep "lease" -A8 | while read LINE
|
|
20 |
cat /var/dhcpd/var/db/dhcpd.leases | grep -v "#" | grep ^lease -A8 | while read LINE
|
|
20 | 21 |
do |
21 | 22 |
HOSTNAMEA=`echo "$LINE" | grep client-hostname | awk '{ print $2 }' | cut -d'"' -f2` |
22 | 23 |
ACTIVEA=`echo "$LINE" | grep active` |
... | ... | |
41 | 42 |
done |
42 | 43 | |
43 | 44 |
# After processed go ahead and tail file looking for changes. |
44 |
tail -F /var/dhcpd/var/db/dhcpd.leases | grep "lease" -A8 | while read LINE
|
|
45 |
tail -F /var/dhcpd/var/db/dhcpd.leases | grep -v "#" | grep ^lease -A8 | while read LINE
|
|
45 | 46 |
do |
46 | 47 |
HOSTNAMEA=`echo "$LINE" | grep client-hostname | awk '{ print $2 }' | cut -d'"' -f2` |
47 | 48 |
ACTIVEA=`echo "$LINE" | grep active` |