bin usr perl use LWP UserAgent use HTTP Response use HTTP Headers use

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/usr/perl
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Headers;
use HTTP::Date;
my $url = @ARGV[0];
my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);
die "Can't get $url\n", "Response tells: ", $response->status_line, "\n" unless $response->is_success;
my $last_md = $response->header('Last-Modified');
if ($last_md) {
$mtime = str2time($last_md);
} else {
$mtime = time;
}
while(1) {
$response = $ua->get($url);
die "Can't get $url\n", "Response tells: ", $response->status_line, "\n" unless $response->is_success;
$ctime = str2time($response->header('Last-Modified'));
if ($ctime != $mtime) {
$mtime = $ctime;
print "Whoa!\n";
}
#print $ctime, "\n";
sleep(1);
}
#print "Last-Modified is ", $last_md, "\n", $mtime, "\n";
#print $dtime, "\n";