#!/usr/bin/perl -w use strict; use LWP::Simple; # file to store the update time my $speaker_prev_mod_time = '/home/qiang/bin/speaker_prev_mod'; # webpage to watch my $speaker_url = 'http://cs.senecac.on.ca/speakers/speakersFlash.html +'; # file to store the update time my $cherry_prev_mod_time = '/home/qiang/bin/cherrypick_prev_mod'; # another webpage to watch my $cherry_url = 'http://cherryavenuefarms.org/'; # update is sent to this email box. my $email = 'your@email.com'; # build the webpage hash my %checks = ( 'seneca speaker series' => { 'time_stamp' => $speaker_prev_mod_time, 'url_to_check' => $speaker_url }, 'cherry picking opening' => { 'time_stamp' => $cherry_prev_mod_time, 'url_to_check' => $cherry_url } ); foreach (my ($k,$v)=each %checks) { my $prev_mod_time = &get_prev($v->{time_stamp}); my $cur_mod_time = &get_current($v->{url_to_check}); if ($cur_mod_time ne $prev_mod_time) { &update_mod_time($cur_mod_time, $v->{time_stamp}); my $t = `/bin/echo "$v->{url_to_check} modified on $cur_mod_time\n" | /bin/mail -s "$k page just updated" $email`; } } # get current update time for the page sub get_current { my $url = shift; my @headers = head($url); scalar localtime($headers[2]); } # get prev update time for the page sub get_prev { my $file_timestamp = shift; unless (-e $file_timestamp) { open F,">$file_timestamp" or die $!; close F; return "bla bla"; } open F,$file_timestamp or die $!; my $mod_time = <F>; close F; return $mod_time; } # record the update time for the page sub update_mod_time { my ($mod_time,$file_timestamp) = @_; open F,">$file_timestamp" or die $!; print F $mod_time; close F; }
In reply to webpage update watch - used to watch event update by Qiang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |