Anmelden

Archiv verlassen und diese Seite im Standarddesign anzeigen : Perl Script für ESX host update



darktemplaaa
06-05-2010, 11:25
Hallo zusammen!

Ich habe mir ein kleines Script geschrieben, um unsere ESXi standalone hosts upzudaten und abzufragen welche bundles schon installiert sind. Bei step 1 kann man die Server abfragen. Bei step 2 verbindet man sich zum Server den man updaten will und installiert alle patches aus seinem repository. Das Problem bei step 2 ist, dass ich wie unten zu sehen die Funktion quotemeta($passwd) verwenden muss, damit er ohne Unterbrechung durchläuft und alle Patche nach der Reihe installiert. Tue ich dies nicht fragt mich das vihostupdate utility beim Start vor jedem patch nach dem Passwort. Der Nachteil bei quotemeta ist jetzt aber, dass man beim Eintippen des Passwortes alles im Klartext sieht. Hat hier noch einer eine Idee wie man es vielleicht hinbekommt? Vielen Dank.




#!/usr/bin/perl
system ("clear");
print "################################################## ################################################## ####
######################################### ESX server patch utility######################################
################################################## ################################################## ####
#This program can query or update ESX and ESXi servers. #
#Following options are available: : #
# 1 = List installed patches of a ESX server #
# 2 = Install all patches of repository /vmware_updates/ESXi #
################################################## ################################################## ####\n";
print "Choose an option from list above: ";
chomp ($select = <STDIN>);
while ($select ne '1' && $select ne '2') {
print "Undefined input!!!\n";
print "Please choose again: ";
chomp($select = <STDIN>);
}
#Listet alle patches
if ($select eq '1') {
print "Server to connect: ";
chomp ($server = <STDIN>);
system ("vihostupdate -q --username root --server $server");
}
#Installiert patches von /vmware-updates/ESXi
if ($select eq '2') {
print "Server to connect: ";
chomp ($server = <STDIN>);
print "Type password: ";
chomp ($passwd = <STDIN>);
$passwd = quotemeta($passwd);
my @patches = glob("/vmware-updates/ESXi/*.zip");
foreach (@patches) {
system "vihostupdate --server $server update --username root --password $passwd -i -b $_ --verbose";
}
}

reneeb
06-05-2010, 13:02
Schau mal hier: http://stackoverflow.com/questions/701078/how-can-i-enter-a-password-using-perl-and-replace-the-characters-with

Das Problem ist nicht das "quotemeta", sondern das mit dem Klartext ist ein Problem, wenn man einfach von STDIN liest...

darktemplaaa
07-05-2010, 09:31
Das gibt ja die keys der characters aus. Am liebsten wäre mir man sieht gar nichts und er speichert dann das Passwort bis das script beendet ist.

Molaf
07-05-2010, 13:05
Hallo,

einfach
print "*(".ord($key).")"; ändern in
print "*";

Gruß,
Molaf

darktemplaaa
10-05-2010, 11:05
Vielen Dank für eure Unterstützung! Ich habe meinen Code um die Vorschläge erweitert und es funktioniert genauso, wie ich es mir vorgstellt habe. Für alle die es noch interessiert und auch gerne ESXi Server updaten wollen hier das Script:



#!/usr/bin/perl

use Term::ReadKey;
my @patches = glob("/vmware-updates/ESXi/*.zip");
system ("clear");
print "################################################## ################################################## ####
########################################ESX server patch utility########################################
################################################## ################################################## ####
#This program can query or update ESX and ESXi servers. #
#Following options are available: : #
# 1 = List installed patches of a ESX server #
# 2 = Install all patches of repository /vmware_updates/ESXi #
################################################## ################################################## ####\n";
print "Choose an option from list above: ";
chomp ($select = <STDIN>);
while ($select ne '1' && $select ne '2') {
print "Undefined input!!!\n";
print "Please choose again: ";
chomp($select = <STDIN>);
}
#List all patches
if ($select eq '1') {
print "Server to connect: ";
chomp ($server = <STDIN>);
system ("vihostupdate -q --username root --server $server");
}
#Install patches from /vmware-updates/ESXi
if ($select eq '2') {
print "Server to connect: ";
chomp ($server = <STDIN>);
chomp ($key = 0);
print "Type password: ";
chomp ($password = "");
ReadMode(4);
while(ord($key = ReadKey(0)) != 10)
{
# For all value of ord($key) see http://www.asciitable.com/
if(ord($key) == 127 || ord($key) == 8) {
# DEL/Backspace was pressed
chop($password);
#2 move the cursor back by one, print a blank character, move the cursor back by one
print "\b \b";
} elsif(ord($key) < 32) {
# Do nothing with these control characters
} else {
$password = $password.$key;
print "*";
}
}
#Ignore additional characters in passwords
$password = quotemeta($password);
ReadMode (0);
# $_ is return value of @patches
foreach (@patches) {
system "vihostupdate --server $server update --username root --password $password -i -b $_ --verbose";
}
}