HI, I need to write a code that will "monitor" file on the web and email me when someone modifies or replaces it. Here's what I had been trying so far:
use LWP::UserAgent; use CGI qw(header -no_debug); use Net::SMTP; #my $url = 'http://130.119.7.69/Autosubscriptions/URLsub/winzip.log'; my $url = 'https://myweb.server.com/URLsub/some.log'; my $res = LWP::UserAgent->new->request(HTTP::Request->new(HEAD => $url +)); my $ServerName = "mySMTP.gateway.com"; my $file="modifiedtest.txt"; # print header; local $\ = "\n"; if ($res->is_success) { # $res->previous && # $res->previous->is_redirect and print 'redirected: ', $res->reques +t->url; $res->last_modified and $modified = scalar(localtime($res->last_mod +ified)); # $res->content_length and print 'size: ', $res->content_length; } else { print $res->status_line; } #read the file content open FILE, $file or die "Couldn't open file: $!"; while (<FILE>){ $string .= $_; } close FILE; #open(DAT, $file) || die("Could not open file!"); #@data=<DAT>; print "file data is $string"; print "web file data is $modified"; #check to see if we have latest info if ($modified = $string) { print "the file is the same"; } else { print "proceeding - file is not the same..."; open(DAT,">$file") || die("Cannot Open File"); print DAT "$modified"; close(DAT); $smtp = Net::SMTP->new($ServerName); die "Couldn't connect to server" unless $smtp; my $MailFrom = "monitor\@netvision.net.il"; my $MailTo = "avishay\@mail.com"; $smtp->mail( $MailFrom ); $smtp->to( $MailTo ); # Start the mail $smtp->data(); # Send the header. $smtp->datasend("To: avishay\@mail.com\n"); $smtp->datasend("From: monitor\@netvision.net.il\n"); $smtp->datasend("Subject: There is new file out there!\n"); $smtp->datasend("\n"); # Send the message $smtp->datasend("New file (time stamped at $modified)\n\n"); # Send the termination string $smtp->dataend(); $smtp->quit(); }
Now, I can not seem to correctely compare between $modified and $string although both prints their values corretcely. What do I miss? Thanks, Sky

In reply to Compare file content with a variable content by Skyhawlk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.