Date: Thu, 21 Feb 2002 10:06:30 +0100 From: Rogier Steehouder <r.j.s@gmx.net> To: "B.K. DeLong" <bkdelong@pobox.com> Cc: freebsd-questions@freebsd.org Subject: Re: BASH programming question Message-ID: <20020221100630.A644@localhost> In-Reply-To: <5.1.0.14.2.20020220214132.029df6f0@pop.earthlink.net>; from bkdelong@pobox.com on Wed, Feb 20, 2002 at 09:43:53PM -0500 References: <20020221000224.A32489@nigsch.com> <5.1.0.14.2.20020220160637.02763050@pop.earthlink.net> <5.1.0.14.2.20020220160637.02763050@pop.earthlink.net> <20020220224520.A31541@nigsch.com> <5.1.0.14.2.20020220165911.01e189a0@pop.earthlink.net> <20020221000224.A32489@nigsch.com> <20020220231436.GA658@raggedclown.net> <5.1.0.14.2.20020220214132.029df6f0@pop.earthlink.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 20-02-2002 21:43 (-0500), B.K. DeLong wrote: > Thanks for all your help - here's the finished script. I know the comments > are a bit anal but I hate having to look all over the place for the same > info again. > > Comments welcome: Well, don't mind if I do :-) > #!/usr/local/bin/bash Why not use plain /bin/sh ? I haven't seen anything bash-specific. #!/bin/sh # Having machine-specific variables in front eases migrating later. IPFILE='/usr/local/bin/.currentip' SERVERNAME='firewall.internal.brain-stream.com' > ifconfig xl0 | grep "inet " | cut -f2 -d" " > /usr/local/bin/.newip NEWIP=$(ifconfig xl0 | grep "inet " | cut -f2 -d" ") # saves writing a file. > if diff /usr/local/bin/.newip /usr/local/bin/.currentip; then exit 0; read OLDIP < ${IPFILE} if [ ${OLDIP} != ${NEWIP} ]; then # saves running 1 program: read is an internal command. > else > cat /usr/local/bin/.newip > /usr/local/bin/.currentip; > mail -s "New IP for firewall.internal.brain-stream.com " ip < > /usr/local/bin/.currentip; > echo "A New IP has been found" > exit 0 > fi echo ${NEWIP} > ${IPFILE} mail -s "New IP for ${SERVERNAME}" ip < ${IPFILE} echo 'A New IP has been found' fi All in all it uses some extra variables, but saves starting one other program and only leaves one file behind. If you use DHCP, you can put all this in /etc/dhclient-exit-hooks and then the new IP is in ${new_ip_address}. That will save running another three programs. With kind regards, Rogier Steehouder -- ___ _ -O_\ // | / Rogier Steehouder //\ / \ r.j.s@gmx.net // \ <---------------------- 25m ----------------------> To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020221100630.A644>