Re: DHClient Exit Scripts
On Aug 17, 2010, at 12:30 PM, Boyd Stephen Smith Jr. wrote: > In <84960162-4435-43b2-a07b-3361f8bda...@halblog.com>, Hal Vaughan wrote: >> 2) It will only run bash scripts. I tried putting a Perl script in that >> directory and it wouldn't work, so I had to put a bash script in that >> directory to run my Perl script. > > This seems wrong. Did your perl script have the correct "she-bang" line as > the first line of the file: #!/usr/bin/perl ? Did it have execute > permissions? I agree, it seems wrong, but that was my experience. I did use the correct she-bang, I even copied that Perl script, as it was, into ~/bin, without changing it. However, the permissions for the scripts in /etc/dhcp3/dhclient-exit-hook.d are all "-rw-r--r--" and owned by root. I had checked to make sure my Perl script matched in ownership and permissions, still no go. Of course, when I put it in my ~/bin directory, I changed the ownership to my account and changed the permissions so it was a "normal" executable. And my bash script I replaced it with in /etc/dhcp3/dhclient-exit-hook.d matched in ownership and permissions to all the other files in that directory. > Like many parts of Debian, I'd expect this to be using run-parts or > equivalent, which simply makes a C/system call to "exec()". On Linux, exec() > handles ELF executables with the +x bit and text files with a "she-bang" line > and the +x bit. But dhclient-script, which is what is run on any event involving the interface, is a bash script, not a C program. I read that it's 255 (or was it 254) lines long when I scanned it in less. There's an exit_with_hooks() function it calls at the end. First it looks for the script /etc/dhcp3/dhclient-exit-hooks and if it exists, it runs it with the routine run_hook(). Then it looks for the directory /etc/dhcp3/dhclient-exit-hooks.d (which, apparently, from comments, is a Debian only thing) and calls run_hookdir() to run the scrips in that directory. For each script, it calls run_hook() to run it. Here's the routine run_hook(): run_hook() { local script="$1" local exit_status shift # discard the first argument, then the rest are the script's if [ -f $script ]; then . $script "$@" fi if [ -n "$exit_status" ] && [ "$exit_status" -ne 0 ]; then logger -p daemon.err "$script returned non-zero exit status $exit_status" save_exit_status=$exit_status fi return $exit_status } I'm not an expert on bash scripting, but if I remember right, the dot command is the same as "source" where, rather than running a script, it run the commands in the script. I could be wrong about that, but if that's the case, then it explains why it executes a bash script and not a Perl script. Hal -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/c6ae9aba-68c4-4b94-8bb8-8c77ed2a9...@halblog.com
Re: DHClient Exit Scripts
In <84960162-4435-43b2-a07b-3361f8bda...@halblog.com>, Hal Vaughan wrote: >2) It will only run bash scripts. I tried putting a Perl script in that >directory and it wouldn't work, so I had to put a bash script in that >directory to run my Perl script. This seems wrong. Did your perl script have the correct "she-bang" line as the first line of the file: #!/usr/bin/perl ? Did it have execute permissions? Like many parts of Debian, I'd expect this to be using run-parts or equivalent, which simply makes a C/system call to "exec()". On Linux, exec() handles ELF executables with the +x bit and text files with a "she-bang" line and the +x bit. (POSIX/SUS Note: a "she-bang" line inhibits any expectation of standard behavior; it makes the entire interpretation of the script system-dependent. On the other hand, exec() is not required to handle scripts at all; a compliant shell must handle the exec() failure and interpret the script itself, but exec() isn't just called by shells.) -- Boyd Stephen Smith Jr. ,= ,-_-. =. b...@iguanasuicide.net ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/\_/ signature.asc Description: This is a digitally signed message part.
Re: DHClient Exit Scripts
On Aug 15, 2010, at 5:41 PM, Hal Vaughan wrote: > I've been reading the man pages for dhclient, but I'm stuck with one key > question I've missed. > > I have an exit script set up to notify me of the IP address of a particular > system (on a LAN) whenever the IP address changes. For now I'm testing, but > in the future it'll be running where I have no control over DHCP or any > servers. This system will be just plugged into the power outlet and into a > CAT5 cable hooked to a hub or switch, so it has to get a dynamic IP address > from the DHCP and it has to be able to alert me to what the new IP address is. > > I know whenever dhclient runs, it runs the exit scripts. The one issue I'm > not clear of is whether the exit scripts will be run any time the IP address > changes, like when a lease expires. I know it'll run at reboot or if > networking is restarted, but will the exit scripts be run when the IP address > is changed by the DHCP? If it's not, is there any program that runs under > those conditions? I had different answers from different people and finally wrote to Ted Lemon, the author of dhclient to clarify. Here is my note to him with his response: - On Aug 16, 2010, at 9:57 AM, Ted Lemon wrote: > On Aug 16, 2010, at 12:05 AM, Hal Vaughan wrote: >> If it is running as a daemon, will it run dhclient-script whenever the IP on >> an interface is changed, such as when the lease runs out or when the DNS >> changes the address for some other reason? > > dhclient-script runs whenever a transaction completes, whether it's an INIT, > an INIT-REBOOT, a RENEW, or a REBIND. It also runs when a transaction times > out, or when the client *fails* to renew a lease. Its purpose in life is to > take whatever happened on a protocol level and translate it into > configuration actions. At renewal, it's responsible for *noticing* that > things have changed, like the DNS server, and updating the resolv.conf file. - A few notes on this: 1) On Debian there is a directory, /etc/dhcp3/dhclient-exit-hooks.d instead of one exit script. Any scripts in that directory will be run when dhclient-script runs, which, as Ted clarified, is on any event involving the interface, instead of just running one script (which would force one to put commands at the end of that one script for each additional script one needs to run). 2) It will only run bash scripts. I tried putting a Perl script in that directory and it wouldn't work, so I had to put a bash script in that directory to run my Perl script. 3) The packages I found that work with DynDNS or similar services mostly ran Perl or Python scripts and were daemons, meaning that using one would mean keeping an instance of Perl or Python in memory, in addition to the needed program. In my case, I'm working on an embedded system, so that's too much memory to use. Since dhclient is used by default on most systems, there's no need for an additional daemon, just a script that dhclient-script can run to update a dynamic DNS service. (Why run two daemons when you need only one?) I may modify one of the scripts in the Debian packages and send the info back to the author in case he wants to let it work with dhclient as an option. Hal -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/84960162-4435-43b2-a07b-3361f8bda...@halblog.com
Re: DHClient Exit Scripts
On Aug 15, 2010, at 6:37 PM, Boyd Stephen Smith Jr. wrote: > In <1af890a5-5bf9-46c9-8c4b-b709170dd...@halblog.com>, Hal Vaughan wrote: >> I've been reading the man pages for dhclient, but I'm stuck with one key >> question I've missed. >> >> I have an exit script set up to notify me of the IP address of a particular >> system (on a LAN) whenever the IP address changes. >> >> I know whenever dhclient runs, it runs the exit scripts. The one issue I'm >> not clear of is whether the exit scripts will be run any time the IP >> address changes, like when a lease expires. I know it'll run at reboot or >> if networking is restarted, but will the exit scripts be run when the IP >> address is changed by the DHCP? If it's not, is there any program that >> runs under those conditions? > > I can't answer the specific question, but I knows that there are DynDNS > clients in Debian that are capable of notifying a remote system whenever the > local system's IP changes. One of these clients should be able to "speak" a > "dialect" you can process. I had always thought those were for external IP addresses, not for inside a LAN. I'll check on that. Thanks! Hal -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/434131f9-b1ad-46bf-901c-ad3be8f07...@halblog.com
Re: DHClient Exit Scripts
In <1af890a5-5bf9-46c9-8c4b-b709170dd...@halblog.com>, Hal Vaughan wrote: >I've been reading the man pages for dhclient, but I'm stuck with one key >question I've missed. > >I have an exit script set up to notify me of the IP address of a particular >system (on a LAN) whenever the IP address changes. > >I know whenever dhclient runs, it runs the exit scripts. The one issue I'm >not clear of is whether the exit scripts will be run any time the IP >address changes, like when a lease expires. I know it'll run at reboot or >if networking is restarted, but will the exit scripts be run when the IP >address is changed by the DHCP? If it's not, is there any program that >runs under those conditions? I can't answer the specific question, but I knows that there are DynDNS clients in Debian that are capable of notifying a remote system whenever the local system's IP changes. One of these clients should be able to "speak" a "dialect" you can process. -- Boyd Stephen Smith Jr. ,= ,-_-. =. b...@iguanasuicide.net ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/\_/ signature.asc Description: This is a digitally signed message part.
DHClient Exit Scripts
I've been reading the man pages for dhclient, but I'm stuck with one key question I've missed. I have an exit script set up to notify me of the IP address of a particular system (on a LAN) whenever the IP address changes. For now I'm testing, but in the future it'll be running where I have no control over DHCP or any servers. This system will be just plugged into the power outlet and into a CAT5 cable hooked to a hub or switch, so it has to get a dynamic IP address from the DHCP and it has to be able to alert me to what the new IP address is. I know whenever dhclient runs, it runs the exit scripts. The one issue I'm not clear of is whether the exit scripts will be run any time the IP address changes, like when a lease expires. I know it'll run at reboot or if networking is restarted, but will the exit scripts be run when the IP address is changed by the DHCP? If it's not, is there any program that runs under those conditions? Thanks! Hal -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/1af890a5-5bf9-46c9-8c4b-b709170dd...@halblog.com