On Sat, 01 Nov 2003 06:02:36 GMT, Bob wrote:
> Do you have an example or someplace I could go to get an example.
See if you have the starting shell script, Try this
locate dhcpcd.exe
you may have to run updatedb to create the database used by locate.
If not, you might look on
http://www.phystech.com/download which seems
to have a tar archive which you could open in a junk directory
and see what you can find.
> I'm too much of a newbie to be able to create one. And have it work.
Well, now is the time to start learning.
http://www.tldp.org/LDP/abs/html/index.html
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.linuxgazette.com/issue52/okopnik2.html
http://www.linuxgazette.com/issue53/okopnik.html
http://www.northernjourney.com/opens...s/newb011.html
http://cfaj.freeshell.org/shell/resources.html
http://www.freeos.com/guides/lsst/
http://www-106.ibm.com/developerwork...ry/l-bash.html
http://www.ccpo.odu.edu/ug/shell_help.html
There are all sorts of ways of writting code to do something.
Usually you code and test in your directory then roll the code into
production.
You can use sed, awk to do text substitutions in files.
Here is just an example showing different things to get you started.
It helps debugging if you make evry check that you can incase you have
errors.
# _work_dir=/etc # production working directory
_work_dir=$HOME # but let's test here
_dhcp_info_fn=/etc/dhcpc/dhcpcd-eth0.info
_my_host=$(hostname) # get my host name
if [ ! -e $_work_dir/hosts_bkup ] ; then
cp /etc/hosts $_work_dir/hosts_bkup # save a copy of hosts file
if [ $? -ne 0 ] ; then
echo " unable to copy /etc/hosts to $_work_dir/hosts_bkup"
exit 1
fi
fi
if [ -e $_dhcp_info_fn ] ; then
. $_dhcp_info_fn # load the ip address info from dhcpcd
else
echo "$_dhcp_info_fn does not exist"
exit 1
fi
#************************************************* ***
#*
#* Now we can fix the host file
#*
#************************************************* ***
/bin/rm $_work_dir/hosts_new # remove new hosts file
touch $_work_dir/hosts_new # create new empty file
if [ $? -ne 0 ] ; then
echo " unable to create $_work_dir/hosts_new "
exit 1
fi
while read line
do
set -a $line # parse each word into $1 $2 $3, . . .
if [ $2 = $_my_host ] ; then # change ip address
echo "$IPADDR $2 $3" >> $_work_dir/hosts_new
else
echo "$line" >> $_work_dir/hosts_new
fi
done < $_work_dir/hosts_bkup
cp $_work_dir/hosts_new $_work_dir/hosts
if [ $? -ne 0 ] ; then
echo " unable to copy $_work_dir/hosts_new to $_work_dir/hosts"
exit 1
fi
exit 0