[prev in list] [next in list] [prev in thread] [next in thread] 

List:       dhcp-users
Subject:    Re: SV: running script at the time of address lease
From:       Tapan <digichip.extreme () gmail ! com>
Date:       2011-02-14 19:21:27
Message-ID: AANLkTim-0kR_fmRTDpZeNhP_bcOKfy9wgUuHpdtzLM9Q () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Many thanks for your answers..
I am using fedora 14 with dhcpd 4.1.1-P1.

On Mon, Feb 14, 2011 at 9:55 PM, Glenn Satchell <glenn.satchell@uniq.com.au>
wrote:
> Hi Jon
>
> execute() was implemented in 3.1.0, so if you tried 3.0.x then it wouldn't
> recognise the command.
>
> It is not possible to get the output of the command executed, but you can
> test the exit status, so you might be able to do something with that.
Syntax
> details are in the dhcp-eval man page.
>
> I found this blog with some examples:
>
>
http://invalidmagic.wordpress.com/2010/03/27/magic-dhcp-stuff-isc-dynamic-host-configuration-protocol/

I also tested with same conf described in the above link. But it didn't
work.
Could anyone confirm, whether the above ex. is working or not or I missed
something.

>
> and this from the mailing list archives which is essentially the same
thing
> posted 2 years earlier:
>
> https://lists.isc.org/pipermail/dhcp-users/2008-September/007167.html
>
> regards,
> -glenn
>
> On 02/15/11 01:16, Jon Otterholm wrote:
>>
>> OK, I tried to make execute work on 3.x without any luck. Seems like it
>> is fixed in 4.x. Is it possible to do conditional leases now? In other
>> words: let an external script decide if the lease is OK or not (for
>> example based on option-82 info).
>>
>> //Jon
>>
>> *Från:*dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@
lists.isc.org
>>
>> [mailto:dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@
lists.isc.org]
>> *För *Denis Laventure
>> *Skickat:* den 14 februari 2011 14:53
>> *Till:* Users of ISC DHCP
>> *Ämne:* RE: running script at the time of address lease
>>
>> What about :
>>
>> on commit { execute("command") } ?
>>
>> from dhcp-eval man page :
>>
>> *execute (/command-path [, data-expr1, ... data-exprN]);/*
>>
>> The *execute* statement runs an external command. The first argument is
>> a string literal containing the name or path of the command to run. The
>> other arguments, if present, are either string literals or data-
>> expressions which evaluate to text strings, to be passed as command-line
>> arguments to the command.
>>
>> *execute*is synchronous; the program will block until the external
>> command being run has finished. Please note that lengthy program
>> execution (for example, in an "on commit" in dhcpd.conf) may result in
>> bad performance and timeouts. Only external applications with very short
>> execution times are suitable for use.
>>
>> Passing user-supplied data to an external application might be
>> dangerous. Make sure the external application checks input buffers for
>> validity. Non-printable ASCII characters will be converted into
>> dhcpd.conf language octal escapes ("777"), make sure your external
>> command handles them as such.
>>
>> It is possible to use the execute statement in any context, not only on
>> events. If you put it in a regular scope in the configuration file you
>> will execute that command every time a scope is evaluated.
>>
>> I’m running ISC DHCPD v. 4.2.0
>>
>> Denis
>>
>> *De :*dhcp-users-bounces+denis_laventure=uqac.ca@lists.isc.org
>> [mailto:dhcp-users-bounces+denis_laventure=uqac.ca@lists.isc.org] *De la
>> part de* Jon Otterholm
>> *Envoyé :* 14 février 2011 06:20
>> *À :* Users of ISC DHCP
>> *Objet :* SV: running script at the time of address lease
>>
>> The short answer is no, but there are ways to solve this.
>>
>> I use the exec function in syslog to execute scripts upon lease/expire.
>> You can configure dhcpd to do logging which includes the information you
>> need (IP, MAC …). Here is an example:
>>
>> Dhcpd.conf
>>
>> ______
>>
>> log-facility local6;
>>
>> on commit { log(info, concat("commit", " ", binary-to-ascii(10, 8, ".",
>> leased-address), " ", concat (
>>
>> suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware, 1,
>> 1))),2),":",
>>
>> suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware, 2,
>> 1))),2),":",
>>
>> suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware, 3,
>> 1))),2),":",
>>
>> suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware, 4,
>> 1))),2),":",
>>
>> suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware, 5,
>> 1))),2),":",
>>
>> suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware, 6,
>> 1))),2)
>>
>> ), " ", "'", (option agent.circuit-id), "'"));
>>
>> }
>>
>> on expiry { log(info, concat("expiry", " ", binary-to-ascii(10, 8, ".",
>> leased-address)));
>>
>> }
>>
>> on release { log(info, concat("expiry", " ", binary-to-ascii(10, 8, ".",
>> leased-address)));
>>
>> }
>>
>> ___________
>>
>> Syslog.conf:
>>
>> ___
>>
>> local6.debug | exec /usr/bin/awk
>> '$6=="commit"{system("/usr/scripts/commit.sh" " " $7 " " $8 " " $9)}'
>>
>> local6.debug | exec /usr/bin/awk
>> '$6=="expiry"{system("/usr/scripts/release.sh" " " $7 " " $8 " " $9)}'
>>
>> ___
>>
Its quite interesting & also a generic way to handle many things.
I tried with rsyslogd ,but ... hard luck here also
>> As you can see dhcpd will log to local6.debug, syslog pipes info to awk
>> that filters info and sends it to a script together with necessary
>> variables. In this example it sends IP, MAC and Option-82 to the script.
>>
>> This runs on our FreeBSD-routers and it works really well. ~1000
>> customers/router and the lease-time is set to max 60min giving us about
>> 2000 leases to handle per hour.
>>
>> The advantage to this solution is the elimination of patches of dhcpd.
>>
>> Hope this info helps, good luck.
>>
>> //Jon
>>
>> *Från:*dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@
lists.isc.org
>>
>> [mailto:dhcp-users-bounces+jon.otterholm=ide.resurscentrum.se@
lists.isc.org]
>> *För *Tapan
>> *Skickat:* den 12 februari 2011 13:11
>> *Till:* dhcp-users@lists.isc.org
>> *Ämne:* running script at the time of address lease
>>
>> Hi list,
>> Is there any way to run a script from dhcpd after an address is assigned
>> to a host ?
>>
>> Regards,
>> Tapan
>>
> _______________________________________________
> dhcp-users mailing list
> dhcp-users@lists.isc.org
> https://lists.isc.org/mailman/listinfo/dhcp-users
>

[Attachment #5 (text/html)]

<span style="color: rgb(0, 0, 153);">Many thanks for your answers..</span><br \
style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">I am using fedora \
14 with dhcpd 4.1.1-P1.</span><br><br>On Mon, Feb 14, 2011 at 9:55 PM, Glenn Satchell \
&lt;<a href="mailto:glenn.satchell@uniq.com.au">glenn.satchell@uniq.com.au</a>&gt; \
wrote:<br> &gt; Hi Jon<br>&gt;<br>&gt; execute() was implemented in 3.1.0, so if you \
tried 3.0.x then it wouldn&#39;t<br>&gt; recognise the command.<br>&gt;<br>&gt; It is \
not possible to get the output of the command executed, but you can<br> &gt; test the \
exit status, so you might be able to do something with that. Syntax<br>&gt; details \
are in the dhcp-eval man page.<br>&gt;<br>&gt; I found this blog with some \
examples:<br>&gt;<br>&gt; <a \
href="http://invalidmagic.wordpress.com/2010/03/27/magic-dhcp-stuff-isc-dynamic-host-c \
onfiguration-protocol/">http://invalidmagic.wordpress.com/2010/03/27/magic-dhcp-stuff-isc-dynamic-host-configuration-protocol/</a><br>
 <br style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">I also \
tested with same conf described in the above link. But it didn&#39;t work.</span><br \
style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);">Could anyone \
confirm, whether the above ex. is working or not or I missed something.</span><br> \
<br>&gt;<br>&gt; and this from the mailing list archives which is essentially the \
same thing<br>&gt; posted 2 years earlier:<br>&gt;<br>&gt; <a \
href="https://lists.isc.org/pipermail/dhcp-users/2008-September/007167.html">https://lists.isc.org/pipermail/dhcp-users/2008-September/007167.html</a><br>
 &gt;<br>&gt; regards,<br>&gt; -glenn<br>&gt;<br>&gt; On 02/15/11 01:16, Jon \
Otterholm wrote:<br>&gt;&gt;<br>&gt;&gt; OK, I tried to make execute work on 3.x \
without any luck. Seems like it<br>&gt;&gt; is fixed in 4.x. Is it possible to do \
conditional leases now? In other<br> &gt;&gt; words: let an external script decide if \
the lease is OK or not (for<br>&gt;&gt; example based on option-82 \
info).<br>&gt;&gt;<br>&gt;&gt; //Jon<br>&gt;&gt;<br>&gt;&gt; \
*Från:*dhcp-users-bounces+jon.otterholm=<a \
href="http://ide.resurscentrum.se">ide.resurscentrum.se</a>@<a \
href="http://lists.isc.org">lists.isc.org</a><br> &gt;&gt;<br>&gt;&gt; [mailto:<a \
href="mailto:dhcp-users-bounces%2Bjon.otterholm">dhcp-users-bounces+jon.otterholm</a>=<a \
href="http://ide.resurscentrum.se">ide.resurscentrum.se</a>@<a \
href="http://lists.isc.org">lists.isc.org</a>]<br> &gt;&gt; *För *Denis \
Laventure<br>&gt;&gt; *Skickat:* den 14 februari 2011 14:53<br>&gt;&gt; *Till:* Users \
of ISC DHCP<br>&gt;&gt; *Ämne:* RE: running script at the time of address \
lease<br>&gt;&gt;<br>&gt;&gt; What about :<br> &gt;&gt;<br>&gt;&gt; on commit { \
execute(&quot;command&quot;) } ?<br>&gt;&gt;<br>&gt;&gt; from dhcp-eval man page \
:<br>&gt;&gt;<br>&gt;&gt; *execute (/command-path [, data-expr1, ... \
data-exprN]);/*<br>&gt;&gt;<br>&gt;&gt; The *execute* statement runs an external \
command. The first argument is<br> &gt;&gt; a string literal containing the name or \
path of the command to run. The<br>&gt;&gt; other arguments, if present, are either \
string literals or data-<br>&gt;&gt; expressions which evaluate to text strings, to \
be passed as command-line<br> &gt;&gt; arguments to the \
command.<br>&gt;&gt;<br>&gt;&gt; *execute*is synchronous; the program will block \
until the external<br>&gt;&gt; command being run has finished. Please note that \
lengthy program<br>&gt;&gt; execution (for example, in an &quot;on commit&quot; in \
dhcpd.conf) may result in<br> &gt;&gt; bad performance and timeouts. Only external \
applications with very short<br>&gt;&gt; execution times are suitable for \
use.<br>&gt;&gt;<br>&gt;&gt; Passing user-supplied data to an external application \
might be<br> &gt;&gt; dangerous. Make sure the external application checks input \
buffers for<br>&gt;&gt; validity. Non-printable ASCII characters will be converted \
into<br>&gt;&gt; dhcpd.conf language octal escapes (&quot;777&quot;), make sure your \
external<br> &gt;&gt; command handles them as such.<br>&gt;&gt;<br>&gt;&gt; It is \
possible to use the execute statement in any context, not only on<br>&gt;&gt; events. \
If you put it in a regular scope in the configuration file you<br> &gt;&gt; will \
execute that command every time a scope is evaluated.<br>&gt;&gt;<br>&gt;&gt; I’m \
running ISC DHCPD v. 4.2.0<br>&gt;&gt;<br>&gt;&gt; Denis<br>&gt;&gt;<br>&gt;&gt; *De \
:*dhcp-users-bounces+denis_laventure=<a href="http://uqac.ca">uqac.ca</a>@<a \
href="http://lists.isc.org">lists.isc.org</a><br> &gt;&gt; [mailto:<a \
href="mailto:dhcp-users-bounces%2Bdenis_laventure">dhcp-users-bounces+denis_laventure</a>=<a \
href="http://uqac.ca">uqac.ca</a>@<a href="http://lists.isc.org">lists.isc.org</a>] \
*De la<br>&gt;&gt; part de* Jon Otterholm<br> &gt;&gt; *Envoyé :* 14 février 2011 \
06:20<br>&gt;&gt; *À :* Users of ISC DHCP<br>&gt;&gt; *Objet :* SV: running script at \
the time of address lease<br>&gt;&gt;<br>&gt;&gt; The short answer is no, but there \
are ways to solve this.<br> &gt;&gt;<br>&gt;&gt; I use the exec function in syslog to \
execute scripts upon lease/expire.<br>&gt;&gt; You can configure dhcpd to do logging \
which includes the information you<br>&gt;&gt; need (IP, MAC …). Here is an \
example:<br> &gt;&gt;<br>&gt;&gt; Dhcpd.conf<br>&gt;&gt;<br>&gt;&gt; \
______<br>&gt;&gt;<br>&gt;&gt; log-facility local6;<br>&gt;&gt;<br>&gt;&gt; on commit \
{ log(info, concat(&quot;commit&quot;, &quot; &quot;, binary-to-ascii(10, 8, \
&quot;.&quot;,<br> &gt;&gt; leased-address), &quot; &quot;, concat \
(<br>&gt;&gt;<br>&gt;&gt; suffix (concat (&quot;0&quot;, binary-to-ascii (16, 8, \
&quot;&quot;, substring(hardware, 1,<br>&gt;&gt; \
1))),2),&quot;:&quot;,<br>&gt;&gt;<br>&gt;&gt; suffix (concat (&quot;0&quot;, \
binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 2,<br> &gt;&gt; \
1))),2),&quot;:&quot;,<br>&gt;&gt;<br>&gt;&gt; suffix (concat (&quot;0&quot;, \
binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 3,<br>&gt;&gt; \
1))),2),&quot;:&quot;,<br>&gt;&gt;<br>&gt;&gt; suffix (concat (&quot;0&quot;, \
binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 4,<br> &gt;&gt; \
1))),2),&quot;:&quot;,<br>&gt;&gt;<br>&gt;&gt; suffix (concat (&quot;0&quot;, \
binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 5,<br>&gt;&gt; \
1))),2),&quot;:&quot;,<br>&gt;&gt;<br>&gt;&gt; suffix (concat (&quot;0&quot;, \
binary-to-ascii (16, 8, &quot;&quot;, substring(hardware, 6,<br> &gt;&gt; \
1))),2)<br>&gt;&gt;<br>&gt;&gt; ), &quot; &quot;, &quot;&#39;&quot;, (option \
agent.circuit-id), &quot;&#39;&quot;));<br>&gt;&gt;<br>&gt;&gt; \
}<br>&gt;&gt;<br>&gt;&gt; on expiry { log(info, concat(&quot;expiry&quot;, &quot; \
&quot;, binary-to-ascii(10, 8, &quot;.&quot;,<br> &gt;&gt; \
leased-address)));<br>&gt;&gt;<br>&gt;&gt; }<br>&gt;&gt;<br>&gt;&gt; on release { \
log(info, concat(&quot;expiry&quot;, &quot; &quot;, binary-to-ascii(10, 8, \
&quot;.&quot;,<br>&gt;&gt; leased-address)));<br>&gt;&gt;<br> &gt;&gt; \
}<br>&gt;&gt;<br>&gt;&gt; ___________<br>&gt;&gt;<br>&gt;&gt; \
Syslog.conf:<br>&gt;&gt;<br>&gt;&gt; ___<br>&gt;&gt;<br>&gt;&gt; local6.debug | exec \
/usr/bin/awk<br>&gt;&gt; \
&#39;$6==&quot;commit&quot;{system(&quot;/usr/scripts/commit.sh&quot; &quot; &quot; \
$7 &quot; &quot; $8 &quot; &quot; $9)}&#39;<br> &gt;&gt;<br>&gt;&gt; local6.debug | \
exec /usr/bin/awk<br>&gt;&gt; \
&#39;$6==&quot;expiry&quot;{system(&quot;/usr/scripts/release.sh&quot; &quot; &quot; \
$7 &quot; &quot; $8 &quot; &quot; $9)}&#39;<br>&gt;&gt;<br>&gt;&gt; ___<br> \
&gt;&gt;<br><font color="#000099">Its quite interesting &amp; </font><span \
style="color: rgb(0, 0, 153);">also a generic way to handle many \
things</span>.<br><span style="color: rgb(0, 0, 153);">I tried with rsyslogd ,but ... \
hard luck here also </span><br> &gt;&gt; As you can see dhcpd will log to \
local6.debug, syslog pipes info to awk<br>&gt;&gt; that filters info and sends it to \
a script together with necessary<br>&gt;&gt; variables. In this example it sends IP, \
MAC and Option-82 to the script.<br> &gt;&gt;<br>&gt;&gt; This runs on our \
FreeBSD-routers and it works really well. ~1000<br>&gt;&gt; customers/router and the \
lease-time is set to max 60min giving us about<br>&gt;&gt; 2000 leases to handle per \
hour.<br>&gt;&gt;<br> &gt;&gt; The advantage to this solution is the elimination of \
patches of dhcpd.<br>&gt;&gt;<br>&gt;&gt; Hope this info helps, good \
luck.<br>&gt;&gt;<br>&gt;&gt; //Jon<br>&gt;&gt;<br>&gt;&gt; \
*Från:*dhcp-users-bounces+jon.otterholm=<a \
href="http://ide.resurscentrum.se">ide.resurscentrum.se</a>@<a \
href="http://lists.isc.org">lists.isc.org</a><br> &gt;&gt;<br>&gt;&gt; [mailto:<a \
href="mailto:dhcp-users-bounces%2Bjon.otterholm">dhcp-users-bounces+jon.otterholm</a>=<a \
href="http://ide.resurscentrum.se">ide.resurscentrum.se</a>@<a \
href="http://lists.isc.org">lists.isc.org</a>]<br> &gt;&gt; *För *Tapan<br>&gt;&gt; \
*Skickat:* den 12 februari 2011 13:11<br>&gt;&gt; *Till:* <a \
href="mailto:dhcp-users@lists.isc.org">dhcp-users@lists.isc.org</a><br>&gt;&gt; \
*Ämne:* running script at the time of address lease<br> &gt;&gt;<br>&gt;&gt; Hi \
list,<br>&gt;&gt; Is there any way to run a script from dhcpd after an address is \
assigned<br>&gt;&gt; to a host ?<br>&gt;&gt;<br>&gt;&gt; Regards,<br>&gt;&gt; \
Tapan<br>&gt;&gt;<br>&gt; _______________________________________________<br> &gt; \
dhcp-users mailing list<br>&gt; <a \
href="mailto:dhcp-users@lists.isc.org">dhcp-users@lists.isc.org</a><br>&gt; <a \
href="https://lists.isc.org/mailman/listinfo/dhcp-users">https://lists.isc.org/mailman/listinfo/dhcp-users</a><br>
 &gt;<br><br>

--20cf304346446c605c049c42c96f--


["dhcp.log" (application/octet-stream)]

_______________________________________________
dhcp-users mailing list
dhcp-users@lists.isc.org
https://lists.isc.org/mailman/listinfo/dhcp-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic