Run script when acquiring DHCP lease?

Nick Guenther kousue at gmail.com
Mon Aug 7 13:04:53 PDT 2006


On 8/7/06, Laurens Vets <laurens at daemon.be> wrote:
> Hi all,
>
> As the subject suggests, I want to run a script when some of my OpenBSD
> machines have acquired a new DHCP lease, something similar to
> ppp.linkup.  The best I came up with was to write a script which checks
> my current ip every x minutes or so and compares that to the one x
> minutes ago.  If they don't match -> run a script which does something
> (e.g. send an email...)
>
> Can't this be done in a simpler way on OpenBSD?
>

hotplugd(8) was my first thought but it only works on attachment of
devices. You might look into scanning /var/db/dhclient.leases.ifname
as documented in dhclient(8) instead of ifconfig. And use cron if you
aren't already, instead of rolling your own timing.

Polling isn't a useless technique, it's just wasteful sometimes.
Remember: "when in doubt, use brute force" [1]

[1] http://www.faqs.org/docs/artu/ch01s06.html

-Nick


More information about the Openbsd-newbies mailing list