Arkevius has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -w use Net::SMTP::SSL; # FETCH THE PUBLIC IP ADDRESS $ip = `wget http://automation.whatismyip.com/n09230945.asp -O - -q ; e +cho`; chomp ($ip); # OPEN FILE THAT CONTAINS THE IP ADDRESS # AS OF THE LAST TIME THE SCRIPT WAS RAN open FILE, "<", "/root/scripts/currentIP" or die $!; $currentIP = <FILE>; chomp ($currentIP); close FILE; # COMPARE THE OLD IP AND THE FETCHED IP # FOR DIFFERENCES if ($currentIP ne $ip) { #IP HAS CHANGED; EMAIL ADMIN THE NEW IP #AND THEN CHANGE THE IP RECORD FILE open FILE, ">", "/root/scripts/currentIP" or die $!; print FILE $ip; close FILE; &emailAdmin; } # E-MAIL SUB ROUTINE # (I HAVE EXIM4 SETUP TO FORWARD TO GOOGLE # SMARTHOST SO I CAN RECEIVE MAIL AS ROOT) sub emailAdmin { my $headers = "PD IP Change\nFrom: ipUpdater Script\nUser-Agent: H +eirloom mailx 12.5 6/20/10\nMIME-Version: 1.0\nContent-Type: text/pla +in; charset=us-ascii\nContent-Transfer-Encoding: 7bit\n"; my $to = "root"; my $body = "The public IP address for the BPDServer has changed.\n +\nNew IP: $ip\nOld IP: $currentIP\n."; system("echo \"$body\" | mail -s \"$headers\" \"$to\""); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script to Notify of Public IP Change
by marto (Cardinal) on Nov 29, 2012 at 16:10 UTC | |
by Arkevius (Initiate) on Nov 29, 2012 at 16:21 UTC | |
by marto (Cardinal) on Nov 29, 2012 at 16:24 UTC | |
|
Re: Script to Notify of Public IP Change
by blue_cowdawg (Monsignor) on Nov 29, 2012 at 18:47 UTC | |
by Arkevius (Initiate) on Nov 29, 2012 at 20:18 UTC | |
|
Re: Script to Notify of Public IP Change
by space_monk (Chaplain) on Nov 29, 2012 at 16:09 UTC | |
by Arkevius (Initiate) on Nov 29, 2012 at 16:19 UTC | |
|
Re: Script to Notify of Public IP Change
by Kenosis (Priest) on Nov 29, 2012 at 16:37 UTC | |
by Arkevius (Initiate) on Nov 29, 2012 at 16:52 UTC |