Voilà, comme j'aime bien automatiser et faire travailler la machine à ma place j'ai fait ce petit script en perl qui va automatiquement télécharger les patches ESX-server :




#!/usr/bin/perl -w


# esx-patchdownloader.pl

Vincent RABAH

use strict;
use LWP::UserAgent;

my $pLength=-1;
my $bReceived=0;
my $kVersion;
my($url,$title);
my($ua,$req,$res);
my $filename;
my $hdl;
my @chksum;

unless( -d "patches")
{
mkdir "patches";
}
Download("http://www.vmware.com/download/vi/vi3_patches_302.html","Downloading …");
print "\n";
print "\n";
print "\n";
print "_____________________________________________________________________________________________________________________________\n";
print " | | |\n";
print "File name : 0% 50% 100%\n";
my @list=GetList("patches/vi3_patches_302.html");
unlink("patches/vi3_patches_302.html");

Create the patchlist.txt file for esx-autoupdate.pl

open FILE, ">patches/patchlist.txt";
for my $i(0..$#list)
{
$list[$i]=~m/.\/(.)../;
printf FILE "%3.3d,$1,$chksum[$i]\n",$i;
}
close FILE;
opendir(DIR,"patches");
my @dir=readdir(DIR);
closedir DIR;
foreach(@list)
{
$_=~m/.
\/(...)/;
if(grep /$1/,@dir )
{
print "$1 already downloaded !\n";
}
else
{
Download($_,"Downloading ");
print "\n";
}
}

sub Download
{
($url,$title)=@_;
$url=~m/.\/(...*)/;
$filename=$1;
print "$filename ";
$pLength=-1;
$bReceived=0;
$ua=LWP::UserAgent->new(env_proxy=>1);
$req=HTTP::Request->new(GET=>$url);
$res=$ua->request($req,&Progress, 1024);
}

sub Progress
{
my($chunk, $res) = @_;
my $length;
$url=~m/.\/(...*)/;
my $file=$1;
if($pLength==-1)
{
open FILE, ">patches/$file";
}
else
{
open FILE, ">>patches/$file";
}
binmode FILE;
print FILE $chunk;
close FILE;
$bReceived += length($chunk);
unless (defined $length)
{
$length = $res->content_length || 0;
}
if ($length)
{
my $nLength=sprintf "%d",100 * $bReceived / $length;
if($pLength!=$nLength || $pLength==-1)
{
if($pLength==-1)
{
$pLength=0;
}
if($filename!~/html/)
{
print "X";
}
$pLength=$nLength;
}
}
}

sub GetList
{
my($file)=@;
my @list;
open FILE, "<$file";
$hdl=select(FILE); $| = 1;
my @html=;
close FILE;
select $hdl;$|=1;
foreach(@html)
{
if($
=~m/http:\/\/download3.vmware.com\/software\/vi\/(.*).tgz/)
{
push(@list,"http://download3.vmware.com/software/vi/$1.tgz");
$_=~m/md5sum:\s(…………………………..)/;
push(@chksum,$1);
}
}
@list=reverse @list;
@chksum=reverse @chksum;
return @list;
}