Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?



On Sat, 23 Sep 2006 00:43:08 +0000 (UTC), Ohmster wrote:
Hey Bit Twister,

I went looking at the google search you sent me on and found this script,
is this what you were suggesting that I run for my computer

That was a script I was running awhile back. This week has been spent
getting Mandriva 2007 Release Candiate 2 working on my firewall.
I have had to change hooks for the new ifcfg-eth0 formats.

and if so, where can I get a good copy of it without line wrap
issues that may be apparent from copying it from a google search?

Here is this weeks copy. Remember, the hooks script is for
whatever you want it to do. What I have done is for my setup.

#*******************************************************************
#*
#* dhclient-exit-hooks - Post processing dhcp client processor
#*
#* Updates /etc/sysconfig/network GATEWAY=new gateway ip address
#* /etc/hosts gets host ip address
#* /etc/resolv.conf has search/domain line removed.
#* and if postix resolv.conf exits, gets new resolv.conf
#* and /etc/hosts file if they differ.
#*
#* This script is called from /sbin/dhclient-script.
#* The variables: exit_status, reason, interface, and new*
#* are set in /sbin/dhclient-script.
#*
#*
#* NOTE:
#* You need to set _lan_nic to your's (eth0, eth1,..)
#*
#*
#* Install:
#* chmod +x dhclient-exit-hooks
#* cp dhclient-exit-hooks /etc/dhclient-exit-hooks
#*
#*
#*******************************************************************

_lan_nic=eth0

if [ $exit_status -eq 0 ] ; then
case $reason in
BOUND|RENEW|REBIND|REBOOT)

#******** change GATEWAY IP in /etc/sysconfig/network ******

_in_fn=/etc/sysconfig/network
_tmp_fn=/tmp/network
/bin/grep -v "GATEWAY=" $_in_fn > $_tmp_fn
/bin/echo "GATEWAY=$new_routers" >> $_tmp_fn
/usr/bin/cmp -s $_tmp_fn $_in_fn
if [ $? -ne 0 ] ; then
/bin/cp $_tmp_fn $_in_fn
fi

#******** change GATEWAY IP in ifcfg-$_lan_nic ******

_in_fn=/etc/sysconfig/network-scripts/ifcfg-$_lan_nic
_tmp_fn=/tmp/ifcfg
_count=$(/bin/grep --count "GATEWAY=" $_in_fn )
if [ $_count -gt 0 ] ; then
/bin/grep -v "GATEWAY=" $_in_fn > $_tmp_fn
/bin/echo "GATEWAY=$new_routers" >> $_tmp_fn
/bin/cp $_tmp_fn $_in_fn
if [ $? -ne 0 ] ; then
/bin/cp $_tmp_fn $_in_fn
fi
fi

#******** change NS_DNSx IPs in ifcfg-$_lan_nic ******

_in_fn=/etc/sysconfig/network-scripts/ifcfg-$_lan_nic
_tmp_fn=/tmp/ifcfg
_count=$(/bin/grep --count "MS_DNS" $_in_fn )
if [ $_count -gt 0 ] ; then
/bin/grep -v "MS_DNS" $_in_fn > $_tmp_fn
_count=0
for d in $new_domain_name_servers ; do
_count=$(( $_count + 1))
/bin/echo "MS_DNS${_count}=$d" >> $_tmp_fn
done
/bin/cp $_tmp_fn $_in_fn
if [ $? -ne 0 ] ; then
/bin/cp $_tmp_fn $_in_fn
fi
fi

#******** strip out search/domain line in /etc/resolv.conf ******

/bin/grep -iv search /etc/resolv.conf \
| /bin/grep -iv domain > /tmp/resolv.conf
/bin/echo "nameserver 66.93.87.2" >> /tmp/resolv.conf
/usr/bin/cmp -s /tmp/resolv.conf /etc/resolv.conf
if [ $? -ne 0 ] ; then
/bin/cp /tmp/resolv.conf /etc/resolv.conf
fi

#********* update postfix with new conf files ****************

if [ -e /var/spool/postfix/etc/resolv.conf ] ; then
/usr/bin/cmp -s /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
if [ $? -ne 0 ] ; then
/bin/cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf
fi
/usr/bin/cmp -s /etc/hosts /var/spool/postfix/etc/hosts
if [ $? -ne 0 ] ; then
/bin/cp /etc/hosts /var/spool/postfix/etc/hosts
fi
fi

#********* update shorewall files ****************
#******************************************************
#* Strip PATH from dhcp.env
#******************************************************

env | sort | grep -v "bin" | sed "s/ /,/g" > /tmp/dhcp.env
chmod 755 /tmp/dhcp.env

/site/bin/update_shorewall $interface
esac
fi

/bin/true

#************* end /etc/dhclient-exit-hooks **************************


I want my hostname to be ohmster.com so will this script not allow me to
do that?

You change the script to do what you want it to do.

Where can I instert my wgets call to bring up my wgets text file
to update my domain IP addresses?


if [ $exit_status -eq 0 ] ; then
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
[ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then

-------- Your code here. ------
fi
fi

Or new and improved

if [ $exit_status -eq 0 ] ; then
case $reason in
BOUND|RENEW|REBIND|REBOOT)

-------- Your code here. ------

esac
fi


What is this script for, where did it come from?

That script used to change the ip address in /etc/hosts file
setting my ISP gateway in /network and changing values
in /etc/shorewall/params file.
The params file is read by the firewall manager shorewall.

Out of my head.
.



Relevant Pages

  • Re: Url shown in message sometimes does not work!!!!
    ... Although Google search for OpenExtLink returned 9370 results I would not ... comment that as you did calling that script common. ... Do you want to say that 9730 messages are common comparing to all the ... > them one more time into Notepad and save the Notepad file as a TXT file on ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
    ... I went looking at the google search you sent me on and found this ... I want my hostname to be ohmster.com so will this script not allow me ... I forgot to munge it out and I really wish that you would not have ... Put "messageforohmster" in message body ...
    (alt.os.linux)
  • Re: external javascript not working
    ... I am interested in the multi line S&R but a quick google search does ... Since you are using Linux, you have various tools that can do it. ... multiple file search and replace (although I can't remember offhand how ... But it's just as easy to write a short script in some language. ...
    (alt.html)
  • XMLHttpRequest issue
    ... XMLHttpRequest to be precise, for a Greasemonkey ... To enhance EVERY Google search result with maybe the digg ... The script code is below. ... var url = godren.stories ...
    (comp.lang.javascript)
  • Re: Hourglass or something?
    ... bars" that you could incorporate, some sophisticated, some ... I did look over the information returned by Paul's Google search, ... script instead of the wscript.exe, which is the standard default WSH ...
    (microsoft.public.scripting.wsh)