Re: DHClient Exit Scripts
On Aug 17, 2010, at 12:30 PM, Boyd Stephen Smith Jr. wrote:
> In <84960162-4435-43B2-A07B-3361F8BDA0BA@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
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():
shift # discard the first argument, then the rest are the script's
if [ -f $script ]; then
. $script "$@"
if [ -n "$exit_status" ] && [ "$exit_status" -ne 0 ]; then
logger -p daemon.err "$script returned non-zero exit status $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.