Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Feb 2002 21:43:53 -0500
From:      "B.K. DeLong" <bkdelong@pobox.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: BASH programming question
Message-ID:  <5.1.0.14.2.20020220214132.029df6f0@pop.earthlink.net>
In-Reply-To: <20020220231436.GA658@raggedclown.net>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi all -

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:

http://www.brain-stream.com/freebsd/2002/scripts/newip

#!/usr/local/bin/bash
# This script was first written by B.K. DeLong (bkdelong@pobox.com) on 
2/20/2002 with help from
# Cliff Sarginson, Florian Nigsch and other members of the 
freebsd-questions@freebsd.org list.
#
# The purpose of this script is if the server reboots when no one is 
around, it will find
# the new IP and email it out to a set alias.
#
# I'm a bit anal with the following comments but that's because as of the 
creation of this
# script, it's all new to me and below is what I had to figure out to get 
this program running.
# I'm a big believer of giving all the details so people can learn
# in the process of doing something new.
#
# Before running this script for the first time, make sure your current ip 
address is in the file ".currentip".
# You can do this by typing "echo your.current.ip > /usr/local/bin/.currentip"
#
# Next, be sure to replace "xl0" with whatever device code designates your 
network card connecting to the Internet
# (most likely through a cable modem or DSL router if you're using this 
script).
#
# Replace "firewall.internal.brain-stream.com with the hostname for this 
particular server or customize
# everything in quotes after "mail -s" with whatever you want the subject 
to be for the mail that will
# notify you of an IP change.
#
# Finally, change the lowercase "ip", (after the mail subject), to whatever 
mail alias you want the email
# alert sent to. This can be "root" or any external email address that you 
can monitor should you not
# be able to get into the system running the script. If you're not actively 
running sendmail or any other
# active mail program, be sure to configure an external SMTP server that 
you can send mail out of.
#
# Look for the following line in your /etc/mail/sendmail.cf file:
#  "Smart" relay host (may be null)
#   DS
#
# And make the following changes:
# DSsmtp:[your.external.smtpserver.com]
#
# If you want to test the script, first "chmod +x" it so you can run it. 
Then put a fake IP in /usr/local/bin/.currentip
# using the above instructions. Run the script nd it should pull your true 
IP, compare it against the fake one
# and send you an email pointing out your real IP.
#
# I have this program running in /etc/crontab with the following configuration:
# *       *       *       *       *       root    /usr/local/bin/newip
#
# This runs the script once a minute to check for a new IP so you don't 
have to wait an half-an-hour or an hour
# for your new address to be mailed to you. You can obviously up the time 
to 5, 10, or even 15 minutes by
# editing the first "*" to the number of minutes desired. Be sure to "kill 
-HUP cron.process.number" to restart cron with
# the new settings.

ifconfig xl0 | grep "inet " | cut -f2 -d" " > /usr/local/bin/.newip

if diff /usr/local/bin/.newip /usr/local/bin/.currentip; then exit 0;

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




--
B.K. DeLong
bkdelong@pobox.com
617.877.3271

http://www.brain-stream.com               Play.
http://www.the-leaky-cauldron.org        Potter.
http://www.attrition.org                       Security.
http://www.artemisiabotanicals.com     Herb.


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?5.1.0.14.2.20020220214132.029df6f0>