Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
- From: Bit Twister <BitTwister@xxxxxxxxxxxxxxxx>
- Date: Sun, 24 Sep 2006 17:26:23 -0500
On Sun, 24 Sep 2006 18:58:45 +0000 (UTC), Ohmster wrote:
so you are saying to just use this tiny bit of script and then put
whatever I want in between the two lines?
Hmmmm, there are 4 lines of code. 8-)
if, case, esac, fi
i.e.: This is the entire script?
Uh, you have to add your lines of code in the indicated area.
---------------------------------------------------------------------
if [ $exit_status -eq 0 ] ; then
case $reason in
BOUND|RENEW|REBIND|REBOOT)
-------- Your code here. ------
esac
fi
---------------------------------------------------------------------
Just that little bit is all I need for an entire dhclient-exit-hooks
file?
Plus code to do what you need done.
Are there any support files that are necessary to go with this
If you are running the dhclient then all you have to do is
create the hooks script with YOUR CODE.
I have not script writing talent like you have. If I try to write my own
script using the piece of code that you gave me above between the lines,
will you help me to proof it to make sure it will work?
I can work with you but you have to understand I do not run/have your
firewall scripts.
By the way, you might have noticed I try to give you fishing lessons,
not catch, skin/gut, fry, then feed you the fish. I will provide
you with instructions on how to help solve your problem and point to
problem areas.
What I need is for the script to do is to update my domains on the
DNS server with my wgets and then restart my firewall. The firewall
has to actually start when a connection is made, and then restart if
the connection has changed. These two actions are separate and
require different lines of code, i.e.:
Alright, there you are. What was provided in the dhcp environment
variable dump which tells you what is going on. :)
What can you look at to see if addresses change.
I know we have been bouncing all around and not sticking to the thread.
I throw out those other tidbits of information for the lurkers and
give you tips on how to make the computer work for you instedad
of the computer working you.
You need to pull your thoughts together, collect and review the
dhclient information provided so far.
You then state what you have to do and look at what was provided to
find the information. Once you look at the information available, you
can then start the coding.
To start firewall initially:
sh /etc/firestarter/firestarter.sh start
To restart a running firewall:
/etc/init.d/firestarter restart
How do I make the script choose the correct action?
You use a case and/or if statement(s) as required. :)
When the computer boots, I need the initial start line. When I get
an IP address change, then I need the restart line.
Very good. What variables can be used to indicate thoses events.
Now, I will assume you have removed the code you put in
/etc/rc.d/rc.local for dumping the dhcp env variables.
All you need right now in the hooks script is to dump the env variables.
You do each activity, boot, network restart, shutdown -r, shutdown -h, ...
and copy the results off to a different file name after each event for
further study.
You already have at least one which has an ip addy change.
One you have those files in your hot little hands, you can use
diff -bBw env.boot env.restart
to see changes to those two files.
NOTE: those were example filenames. I have no idea what you will/have
named your files.
Now for debuging your script(s).
It is a good idea to break your program into manageable pieces
so they can be sepearated and tested by themselves instead
of making it one big program. Example: your wget code would
be in a script and called from the hooks script.
You can put an echo statement on commands to show you what will happen
instead of having the commands execute. Example:
if [ "$some_var" = "some_value" ] ; then
echo sh /etc/firestarter/firestarter.sh start
fi
if [ "$some_var" = "some_value" ] ; then
echo /etc/init.d/firestarter restart
fi
or use a case statement
case $some_var in
some_value_1|some_value_2)
echo sh /etc/firestarter/firestarter.sh restart
;;
*)
if [ ! -e "/sone/firestarter/lock.file" ] ; then
echo sh /etc/firestarter/firestarter.sh start
;;
esac
If firestarter does not have a lock file, you could use something
like
pgrep firestarter
if [$? -ne 0 ] ; then
echo sh /etc/firestarter/firestarter.sh start
fi
These are just examples of how to hunt down things and
not to be confused with actual code that you need.
When you have a problem around one section of code you can do a
set -vx
lines of code to
look at here
set -
That will show you what is going on between the two set commands.
Once you have collected your test data from the env dumps. You could
write a test harness/script to ring out your code.
You have an environment dump you can use to write your test harness.
You put those variables at the top, call the hooks script, change a
variable(s) and call the hooks script,... until you have covered all your
bases. Example:
cat test_hooks
#!/bin/bash
#***********************************************************************
#*
#* env values pulled from a dhclient env dump in /etc/dhclient-exit-hooks
#* with the commands
#* echo "---------------" >> /tmp/env.results
#* date >> /tmp/env.results
#* env | sort >> /tmp/env.results
#* in /etc/dhclient-exit-hooks
#*
#***********************************************************************
#****************************************
#*
#* Default env value setup
#*
#****************************************
PATH=/af/asf:/a/fa/fa:/f/af/asf/
export PATH
new_broadcast_address=255.255.255.255
new_dhcp_lease_time=277534
new_dhcp_message_type=5
new_dhcp_server_identifier=68.87.66.10
new_domain_name=hsd1.tx.comcast.net.
new_domain_name_servers="68.87.175.98 68.183.69.146"
new_expiry=1159328517
new_ip_address=71.236.4.40
new_network_number=71.236.4.0
new_routers=71.236.4.1
new_subnet_mask=255.255.254.0
new_time_offset=-18000
pid=2434
reason=REBOOT
#****************************************
#*
#* main testing starts here
#*
#****************************************
echo Test 1 $reason
/etc/dhclient-exit-hooks
some_var_here=new_test_value
someother_var_here=new_test_value
echo Test 2 testing some_var_here = $some_var_here
/etc/dhclient-exit-hooks
Once you decide it looks like it is working,
you remove the "echo" statements from your dhclient-exit-hooks scripts
Example:
before
if [ "$some_var" = "some_value" ] ; then
echo sh /etc/firestarter/firestarter.sh start
fi
after
if [ "$some_var" = "some_value" ] ; then
sh /etc/firestarter/firestarter.sh start
fi
Now, you have the http://tldp.org/LDP/abs/html/index.html link
and doing a man test
that should get you a coding start.
Looking/greping through /etc/init.d
scripts can provide syntax/coding examples from better people than I.
I suggest reading all man pages about dhclient to get some baseline
knowledge and decide what your test cases/hoos code might need:
I would do a quick read of /sbin/dhclient-script then
locate dhclient | grep /man
will suggest some man pages to read. Example:
/usr/share/man/man8/dhclient-script.8.bz2
man dhclient-script
.
- References:
- Prev by Date: Stats alt.os.linux (last 7 days)
- Next by Date: Re: Mission critical ...
- Previous by thread: Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
- Next by thread: Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
- Index(es):
Relevant Pages
|