<[EMAIL PROTECTED]> wrote:
> On Wed, 27 Feb 2002, Tom Badran wrote:
> > What im trying to do is get an email sent to me every time the IP changes on
> > a specific machine, so i always have a record of it for logging in via ssh.
> > The specific connection is ppp0 which auto redials on disconnect. If there is
> > an easier way of doing this please share with me.
> >
> I.e.
> IP=`ifconfig eth0|grep "inet addr"|cut -d: -f2|cut -d' ' -f1`
> (or something equally ugly)
>
> Then do something like:
>
> Old_IP=`cat $FILENAME`
>
> [ "$IP" == "$OLD_IP" ]; then do_something
Oh. Duh. If I'd read the email closer, I'd have posted THIS script instead:
[root@fw antispam]# cat /etc/rc.d/init.d/what.a.hack
#!/bin/bash
newip=`/sbin/ifconfig ppp0 | /bin/egrep 'inet addr' | /bin/sed 's/inet addr://' |
/bin/awk '{print $1}'`
if [ ".$newip" = "." ] ; then
echo oops - newip is blank again
# this happens more than I would like, one of these days I will figure out why.
exit -1
fi
oldip=`cat /tmp/current.ip`
if [ "$newip" == "$oldip" ] ; then exit 0 ; fi
echo $newip >> /etc/rc.d/init.d/iplog
/bin/sed "s/FARBOO/$newip/" /etc/rc.d/init.d/rc.fw.basehack > /root/rc.hacko
echo $newip > /tmp/current.ip
chmod 700 /root/rc.hacko
/sbin/ipchains -L -n -v -x
/root/rc.hacko
echo $newip | elm [EMAIL PROTECTED]
And I run that in a cron job. Here's my crontab entry:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /etc/rc.d/init.d/what.a.hack
Yeah, its quite a hack. But it does the trick of resetting my firewall rules
whenever the ip addr changes, and it notifies me, and everything.
There's probably much better ways to do this, but I got it working this way
and have no plan to fix it ;-)
rc
Want to buy your Pack or Services from MandrakeSoft?
Go to http://www.mandrakestore.com