home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_utl.zip / lwp-mirror.cmd < prev    next >
OS/2 REXX Batch file  |  1997-11-28  |  3KB  |  108 lines

  1. extproc perl -S
  2. #!f:/perllib/bin/perl -w
  3.     eval 'exec perl -S $0 "$@"'
  4.     if 0;
  5.  
  6. # $Id: lwp-mirror.PL,v 1.17 1997/09/20 11:04:34 aas Exp $
  7. #
  8. # Simple mirror utility using LWP
  9.  
  10. =head1 NAME
  11.  
  12. lwp-mirror - Simple mirror utility for WWW
  13.  
  14. =head1 SYNOPSIS
  15.  
  16.  lwp-mirror [-v] [-t timeout] <url> <local file>
  17.  
  18. =head1 DESCRIPTION
  19.  
  20. This program can be used to mirror a document from a WWW server.  The
  21. document is only transfered if the remote copy is newer than the local
  22. copy.  If the local copy is newer nothing happens.
  23.  
  24. Use the C<-v> option to print the version number of this program.
  25.  
  26. The timeout value specified with the C<-t> option.  The timeout value
  27. is the time that the program will wait for response from the remote
  28. server before it fails.  The default unit for the timeout value is
  29. seconds.  You might append "m" or "h" to the timeout value to make it
  30. minutes or hours, repectively.
  31.  
  32. Because this program is implemented using the LWP library, it only
  33. supports the protocols that LWP supports.
  34.  
  35. =head1 SEE ALSO
  36.  
  37. L<lwp-request>, L<LWP>
  38.  
  39. =head1 AUTHOR
  40.  
  41. Gisle Aas <aas@a.sn.no>
  42.  
  43. =cut
  44.  
  45.  
  46. use LWP::Simple;
  47. use Getopt::Std;
  48.  
  49. $progname = $0;
  50. $progname =~ s,.*/,,;  # use basename only
  51. $progname =~ s/\.\w*$//; #strip extension if any
  52.  
  53. $VERSION = sprintf("%d.%02d", q$Revision: 1.17 $ =~ /(\d+)\.(\d+)/);
  54.  
  55. $opt_h = undef;  # print usage
  56. $opt_v = undef;  # print version
  57. $opt_t = undef;  # timeout
  58.  
  59. unless (getopts("hvt:")) {
  60.     usage();
  61. }
  62.  
  63. if ($opt_v) {
  64.     require LWP;
  65.     my $DISTNAME = 'libwww-perl-' . LWP::Version();
  66.     die <<"EOT";
  67. This is lwp-mirror version $VERSION ($DISTNAME)
  68.  
  69. Copyright 1995-1996, Gisle Aas.
  70.  
  71. This program is free software; you can redistribute it and/or
  72. modify it under the same terms as Perl itself.
  73. EOT
  74. }
  75.  
  76. $url  = shift or usage();
  77. $file = shift or usage();
  78. usage() if $opt_h or @ARGV;
  79.  
  80. if (defined $opt_t) {
  81.     $opt_t =~ /^(\d+)([smh])?/;
  82.     die "$progname: Illegal timeout value!\n" unless defined $1;
  83.     $timeout = $1;
  84.     $timeout *= 60   if ($2 eq "m");
  85.     $timeout *= 3600 if ($2 eq "h");
  86.     $LWP::Simple::ua->timeout($timeout);
  87. }
  88.  
  89. $rc = mirror($url, $file);
  90.  
  91. if ($rc == 304) {
  92.     print STDERR "$progname: $file is up to date\n"
  93. } elsif (!is_success($rc)) {
  94.     print STDERR "$progname: $rc ", status_message($rc), "   ($url)\n";
  95.     exit 1;
  96. }
  97. exit;
  98.  
  99.  
  100. sub usage
  101. {
  102.     die <<"EOT";
  103. Usage: $progname [-options] <url> <file>
  104.     -v           print version number of program
  105.     -t <timeout> Set timeout value
  106. EOT
  107. }
  108.