[j-nsp] JUNOS download script

hayter hayter at usc.edu
Sun Aug 3 20:42:03 EDT 2003


here's a Perl script to mirror code and documentation from Juniper.
it needs a bunch of modules, WWW::Mechanize::Shell and IO::Socket::SSL
should cover the needs.

edit script for username/password, version and documentation type.

...
my $user = '*username-here*';
my $pass = '*password-here*';

my $ver = '6.0';       # lazy version matching
my $ext = 'tgz';       # pdf|tgz documentation
...

give it a try:

$ perl juniper-download.mechanize 
mirroring jinstall-6.0R1.3-domestic-signed.tgz
mirroring jinstall-6.0R1.3-domestic-signed.tgz.md5
mirroring jbundle-6.0R1.3-domestic-signed.tgz
mirroring jbundle-6.0R1.3-domestic-signed.tgz.md5
mirroring install-media-6.0R1.3-domestic
mirroring install-media-6.0R1.3-domestic.md5
mirroring juniper-mibs-6.0R1.3-signed.tgz
mirroring juniper-mibs-6.0R1.3-signed.tgz.md5
mirroring errmsg-xml-6.0R1.3.tgz
mirroring errmsg-xml-6.0R1.3.tgz.md5
mirroring junoscript-perl-6.0R1.3-domestic.tar.gz
mirroring junoscript-perl-6.0R1.3-domestic.tar.gz.md5
mirroring junoscript-perl-prereqs-6.0R1.3-domestic.tar.gz
mirroring junoscript-perl-prereqs-6.0R1.3-domestic.tar.gz.md5
mirroring swconfig60-comprehensive-index.pdf
mirroring feature-guide-60.tgz
mirroring swconfig60-getting-started.tgz
mirroring swconfig60-mpls-apps.tgz
mirroring swconfig60-multicast.tgz
mirroring swconfig60-interfaces.tgz
mirroring swconfig60-net-mgmt.tgz
mirroring swconfig60-policy.tgz
mirroring swconfig60-routing.tgz
mirroring swconfig60-services.tgz
mirroring swconfig60-vpns.tgz
mirroring swcmdref60.tgz
mirroring swcmdref60-interfaces.tgz
mirroring syslog-messages60.tgz
mirroring junoscript60-guide.tgz
mirroring junoscript60-ref.tgz
mirroring rn-sw-60.pdf

it's not very bright, i'll try and add some robustness somday (patches
welcome).

currently assumes you want the Domestic Encrypted branch of software.

----
Carl Hayter
ISD - Data Network Operations
University of Southern California
-------------- next part --------------
#!perl
use strict;
use warnings;
$|++;

my $user = '*username-here*';
my $pass = '*password-here*';

my $ver = '6.0';       # lazy version matching
my $ext = 'tgz';       # pdf|tgz documentation

use WWW::Mechanize;
use WWW::Mechanize::FormFiller;
use URI::URL;

my $agent = WWW::Mechanize->new();
my $formfiller = WWW::Mechanize::FormFiller->new();

$agent->env_proxy();

$agent->agent('Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)');

$agent->get('https://www.juniper.net/support/');

$agent->form(2);
$formfiller->add_filler( 'USER' => Fixed => $user );
$formfiller->add_filler( 'PASSWORD' => Fixed => $pass );
$formfiller->fill_form($agent->current_form);
$agent->submit();

$agent->follow(qr(Download software));
$agent->follow(qr(Encrypted));

my @links;
my @all_links = $agent->links();

my @targets = grep {
    m!\Q$ver! and m!\Q//download.juniper.net/!
    } map {$_->[0]} @all_links;

$agent->follow(qr(Software Documentation: Release \Q$ver\E));
@all_links = $agent->links();

push @targets, grep {
    m!\Q-comprehensive-index.pdf! or
    ( m!/download/! and m!$ext$! ) or
    m!/download/rn-sw-\d+\.pdf!
    } map {$_->[0]} @all_links;

# uncomment line below for testing
#  print join $/, @targets, ''; exit;

my $base = $agent->uri;
for my $target (@targets) {
	my $url = URI::URL->new($target,$base);
	$target = $url->path;
	$target =~ s!^(.*/)?([^/]+)$!$2!;
	$url = $url->abs;
	print "mirroring $target$/";
	$agent->mirror($url,$target);
};


More information about the juniper-nsp mailing list