use LWP::Simple;
use MIME::Lite;
use strict;
my $pageurl = "http://fruit.alsacreations.fr/";
my $logfile = 'log.pl.txt';
my @recipients = ("dew\@rabbit.com","tarzan\@rabbit.com");
sub trim($) {
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
return $str;
}
my $content = get $pageurl;
if($content =~ /
(.*)<\/title>/) {
my $title = $1;
} else {
my $title = '';
}
open(F,"<".$logfile) or print "Cannot read file";
my $last_title = trim(readline(F));
close(F);
if($last_title ne $title) {
print "Difference\n";
foreach my $recipient (@recipients) {
print "Mail to ".$recipient."\n";
my $msg = new MIME::Lite
From => 'dumbo@jumbo.com',
To => $recipient,
Subject => '[Turborabbit] New title !',
Type => 'TEXT',
Data => "(Script Perl) New title !\n".$title."";
$msg -> send;
}
open(FP,">".$logfile);
print FP $title;
close(FP);
}