eric@lucii.org on Tue, 26 Aug 2003 09:56:06 -0400 |
On Tue, Aug 26, 2003 at 09:05:01AM -0400, JP Toto wrote: > I don't think I can offer an intelligent solution to this problem but I > would love to see the script. Any chance you could post it for us? Sure: I call it IPChangeNotification and it runs by cron hourly. The file that the IP is stored in (changable) is /etc/thisIP. ---------------file-------------------- #!/usr/bin/perl $CONF = "/sbin/ifconfig" ; $IF = "ppp0" ; ## or eth0, or eth1, or ... $IPfile = "/etc/thisIP" ; $ADMIN = 'ADMIN@wherever.com' ; $SERVER = qx|hostname --fqdn| ; chomp $SERVER ; # figure out the IP address... $THIS=qx|$CONF $IF \|grep "inet addr" | ; @UNOparse = split ':', $THIS ; $THIS = $UNOparse[1] ; @DOSparse = split ' ', $THIS ; $ThisIP = $DOSparse[0] ; # Open the ip file to get the "old" IP (assume no IP if file does not exist) if ( -r $IPfile ) { open IPFILE, "<$IPfile" or die "Appears I cannot read or create the $IPfile file... bummer\n" ; $OldIP = <IPFILE> ; close IPFILE ; chomp $OldIP ; }else{ print "no previous IP stored... it will be stored in $IPfile\n" ; $OldIP = "" ; } # Compare current IP to the old IP and act appropriately if ( $ThisIP eq $OldIP ) { print "IP did match... nothing else to be done!\n" ; }else { print "IP did NOT match...\n" ; open IPFILE, ">$IPfile" or die 'cannot create $IPfile ... become root or something\n' ; printf IPFILE "$ThisIP" ; close IPFILE ; print "Mailing notice of change to $ADMIN\n" ; open TF, '>/tmp/tempemail' or die ; printf TF "The IP address for the $SERVER server has changed to $ThisIP\n" ; close TF ; qx|mail '$ADMIN' < /tmp/tempemail | ; } exit 0 ; ---------------end file-------------------- -- # Eric Lucas # "Oh, I have slipped the surly bond of earth # And danced the skies on laughter-silvered wings... # -- John Gillespie Magee Jr. _________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce General Discussion -- http://lists.netisland.net/mailman/listinfo/plug
|
|