Vous êtes passionnés comme moi de machines basse-consommation, ARM, Atom : rendez visite à mon partenaire !
Script de téléchargement automatique de patch esx server
vendredi 19 octobre 2007 à 07:19 | VirtualisationVoilà, 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;
}
A propos de Vincent RABAH
Je suis DSI depuis 10 ans. Spécialiste en systèmes d'information et réseaux.
Expert en management, GreenIT et virtualisation de serveurs. Vous pouvez consulter l'ensemble de mon parcours.
I do speak English even if my blog is written in French ... Feel free to leave comments, I'll answer you !
- OpenXenManager et XenWebManager
- SDK Ruby pour VMware vSphere API
- Belle infographie Citrix XenServer
- Démonstration de la compression mémoire VMware
- VMworld 2010 - Day 1
- Nouvelle version de Veeam Backup & Restore
- Sécuriser VMware vSphere 4.1
- Client vCenter pour iPad en version béta
- SDK PHP pour VMware vCloud
- Performance Best Practice vSphere 4.1
Vous pouvez lire également :
Partagez cet article :




