Permalink
Cannot retrieve contributors at this time
#!/usr/bin/perl | |
# | |
# wget-monitor -- simple URL monitor | |
# | |
# Stick a list of URLs in ~/.wget-monitor, one per line, (blank lines | |
# and comment lines with '#' allowed) for wget to retrieve. First | |
# invocation fetches the URLs into a local cache; subsequent | |
# invocations diff the online version against the cache. | |
# | |
# Copyright (c) 2003 Adam Spiers <adam@spiers.net> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
use strict; | |
use warnings; | |
use File::Basename; | |
use File::Path; | |
use File::Temp 'tempdir'; | |
open(CFG, "$ENV{HOME}/.wget-monitor") | |
or die "$0: $!\n"; | |
my $cache = "$ENV{HOME}/.wget-monitor-cache"; | |
-d $cache or mkdir $cache; | |
my $tempdir = tempdir("/tmp/wget-monitor-XXXXXXX", CLEANUP => 1); | |
my $changes = 0; | |
while (<CFG>) { | |
next if /^\s*#/ || /^\s*$/; | |
chomp; | |
m!^((http|ftp):)//! or die "Weird line $.:\n$_\n"; | |
my $proto = $1; | |
chdir $tempdir or die "chdir($tempdir) failed: $!\n"; | |
my $wget = `wget -nv -x "$_" 2>&1`; | |
my ($path) = $wget =~ /-> "(.+)"/ | |
or die "Weird output from wget:\n$wget\n"; | |
my $new = "$tempdir/$path"; | |
my $old = "$cache/$proto/$path"; | |
if (-e $old) { | |
my $diff = `diff -u "$old" "$new"`; | |
if ($diff) { | |
$changes++; | |
$diff =~ s!^--- $cache/!--- !m; | |
print $diff; | |
} | |
} | |
else { | |
my $dir = dirname($old); | |
mkpath($dir, 0, 0700) or die "mkpath($dir) failed: $!\n"; | |
} | |
rename $new, $old | |
or warn "rename($new, $old) failed: $!\n"; | |
} | |
exit $changes; |