[ale] Perl Equality
James P. Kinney III
jkinney at localnetsolutions.com
Mon Oct 27 08:42:33 EST 2003
Here's my version in bash:
#!/bin/sh
# A simple IP checking script
# Copyright 2001 Local Net Solutions
# Licensed under the GPL v1.0 or later
# See http://www.gnu.org/licenses/licenses.html for license details
IP=`/sbin/ifconfig ppp0 | grep addr |sed s/addr:// | sed s/inet\ // |
sed s/P-t-P:[0-9]*.[0-9]*.[0-9]*.[0-9]*// | sed
s/Mask:[0-9]*.[0-9]*.[0-9]*.[0-9]*//`;
echo $IP >& ppp0-IP.new;
IP_old=`cat ppp0-IP`;
if [ $IP == $IP_old ]; then
echo "New and old IPs match\n";
else
echo "Update IP host";
echo "Subject: IP update" >&sendstuff
echo `hostname` "$IP" `date` >>sendstuff
/usr/sbin/sendmail iplist at mydomain.com <sendstuff
echo $IP >& ppp0-IP
fi
On Mon, 2003-10-27 at 08:08, Robert Coggins wrote:
> Hey all...
>
> I have this script I wrote in cron to run every hour. Most of the time
> the it works like I want it to. Although there are some times that it
> will send me an email but everything looks like it is equal. Do any of
> you have a suggestion as to why this is howing as eqal? Thanks for the
> help!
>
> -Rob
>
> # Programmed by: Robert Coggins.
> # This program is to check the external IP address of my system.
> # If the IP is the same do nothing.
> # If the IP is different email it and store new IP in a file
>
> #!/usr/bin/perl
> use LWP::Simple;
>
> $WORK_PATH='/path/to/external_ip';
> $EMAIL_ADD='anemail at address.com';
> $EMAIL_FROM='from at address.com';
> $EMAIL_REPLY='from at address.com';
> $EMAIL_SUBJ='This is the current IP!';
> $EMAIL_MESG='This is the current ip: ';
>
> $file_cur = get('http://checkip.dyndns.org');
> $file_cur =~ tr#a-zA-Z< >\t\n/:=##d;
> open(infile, "< $WORK_PATH/theip");
> $file_old = <infile>;
> $file_old =~ tr#a-zA-Z< >\t\n/:=##d;
> close(infile);
>
> print $file_cur;
> print $file_old;
>
> if($file_cur eq $file_old){
> print "The ips are the same.\n";
> }
> else{
>
> open(outfile, "> $WORK_PATH/theip");
> print outfile $file_cur;
> close(outfile);
>
> open(SENDMAIL, "| /usr/sbin/sendmail -t -n") || die "Unable to open
> sendmail";
> print SENDMAIL "From: $EMAIL_FROM\n";
> print SENDMAIL "To: $EMAIL_ADD\n";
> print SENDMAIL "Reply-To: $EMAIL_REPLY\n";
> print SENDMAIL "Subject: $EMAIL_SUBJ\n\n";
> print SENDMAIL "$EMAIL_MESG $file_cur";
> close(MAIL);
> }
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
--
James P. Kinney III \Changing the mobile computing world/
CEO & Director of Engineering \ one Linux user /
Local Net Solutions,LLC \ at a time. /
770-493-8244 \.___________________________./
http://www.localnetsolutions.com
GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics)
<jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
More information about the Ale
mailing list