3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
6 # Simple mirror utility using LWP
10 lwp-mirror - Simple mirror utility
14 lwp-mirror [-v] [-t timeout] <url> <local file>
18 This program can be used to mirror a document from a WWW server. The
19 document is only transfered if the remote copy is newer than the local
20 copy. If the local copy is newer nothing happens.
22 Use the C<-v> option to print the version number of this program.
24 The timeout value specified with the C<-t> option. The timeout value
25 is the time that the program will wait for response from the remote
26 server before it fails. The default unit for the timeout value is
27 seconds. You might append "m" or "h" to the timeout value to make it
28 minutes or hours, respectively.
30 Because this program is implemented using the LWP library, it only
31 supports the protocols that LWP supports.
35 L<lwp-request>, L<LWP>
39 Gisle Aas <gisle@aas.no>
44 use LWP::Simple qw(mirror is_success status_message $ua);
48 $progname =~ s,.*/,,; # use basename only
49 $progname =~ s/\.\w*$//; #strip extension if any
53 $opt_h = undef; # print usage
54 $opt_v = undef; # print version
55 $opt_t = undef; # timeout
57 unless (getopts("hvt:")) {
63 my $DISTNAME = 'libwww-perl-' . LWP::Version();
65 This is lwp-mirror version $VERSION ($DISTNAME)
67 Copyright 1995-1999, Gisle Aas.
69 This program is free software; you can redistribute it and/or
70 modify it under the same terms as Perl itself.
74 $url = shift or usage();
75 $file = shift or usage();
76 usage() if $opt_h or @ARGV;
79 $opt_t =~ /^(\d+)([smh])?/;
80 die "$progname: Illegal timeout value!\n" unless defined $1;
82 $timeout *= 60 if ($2 eq "m");
83 $timeout *= 3600 if ($2 eq "h");
84 $ua->timeout($timeout);
87 $rc = mirror($url, $file);
90 print STDERR "$progname: $file is up to date\n"
92 elsif (!is_success($rc)) {
93 print STDERR "$progname: $rc ", status_message($rc), " ($url)\n";
102 Usage: $progname [-options] <url> <file>
103 -v print version number of program
104 -t <timeout> Set timeout value