On 2014-06-23, Kenneth Westerback <kwesterb...@gmail.com> wrote:
> Alternatively you can monitor the leases file or use the '-L' option
> to write out the offered and effective lease information if you want
> complete information on what is being received and used. Some people
> use the entr port (/usr/ports/sysutils/entr, http://entrproject.org/)
> to monitor the file(s).

FWIW, I'm doing this to monitor nameserver changes, here's an example.
Note that it relies on support that was added to dhclient post-5.5.

(entr is from packages; it's a nice simple kqueue watcher, so it
works by a trigger when the file is changed, rather than needing to
poll it periodically).

$ cat /etc/dhcp-watcher                                      
#!/bin/sh
gw=$(route -n get -inet 0.0.0.0 | awk '/interface/ {print $2}')
dns=$(awk '/domain-name-servers/ {gsub("[;,]", " ", $3); print $3;}' 
/etc/dhclient.lease.$gw)
unbound-control forward_add . $dns > /dev/null
echo "default now on $gw: $(unbound-control list_forwards)" | logger -t 
dhcp-watcher

$ cat /etc/dhcp-watcher.run                                  
#!/bin/sh
/etc/dhcp-watcher
echo /etc/dhclient.lease.* | tr ' ' '\n' | entr /etc/dhcp-watcher

$ cat /etc/hostname.em0                                                         
                     
up -autoconfprivacy
!dhclient -L /etc/dhclient.lease.em0 em0
rtsol

$ cat /etc/hostname.iwn0                                                        
                     
nwid rarara wpakey ackackmacaque wpaprotos wpa2 wpaciphers ccmp
!dhclient -L /etc/dhclient.lease.iwn0 iwn0
rtsol

Reply via email to