Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/11/2004, 07:53
startwav
 
Fecha de Ingreso: junio-2003
Mensajes: 122
Antigüedad: 21 años, 9 meses
Puntos: 0
abrir fichero en perl e insertar cadena, AYUDA,-!!

Hola,

tengo un fichero programado en perl que me lanza un telnet a unos equipos mios y les agrega configuraciones, las que les indique, el caso es que quiero introducir ahora una opción que les indique que las configuraciones las lea de unos ficheros que previamente le paso yo, "variable" y "variable2", mo podéis echar una mano para ponerlo de tal forma que me lea esos ficheors y despues los inserte en los campos que he puesto...

os pego el fichero en perl para que le echeis una mano:

#campos[0]->Hostname
#campos[1]->IP
#campos[3]->Password

#!/usr/bin/perl
use Net::Telnet ();
$variable='/paquetes/script/codigo.txt';
#while ($linea=<VARIABLE>)
$entrada='/paquetes/script/mxulraxXXX.txt';
open(entrada) || die "ERROR: FALTA INPUT.CSV";
while ($linea=<entrada>)
open (VARIABLE, "<$variable") || die "No PUDO LEER FICHERO" ;
while ($linea2=<VARIABLE>)
{
chomp $linea;
@campos=(split /;/,$linea);
$hostname=$campos[NOMBRE];
$router=$campos[10.132.12.50];
$user='opx25';
$pass1='opera1ya';
$pass2=$campos[XXXXXX];
printf "Configurado de $hostname->";
$k=configura($router,$pass1,$pass2,$user,$hostname );
}
exit;


sub configura {

$t = new Net::Telnet (-timeout => 10,-prompt => '/.*[>#]$/',-Errmode => 'return');
$t->open($_[0]);
$log="$_[4].log";
$fh = $t->input_log($log);

## Login.
($prematch, $match) = $t->waitfor(-match => '/username: $/i',-match => '/password: $/i');
if ($match =~ /username: $/i)
{
$t->print("$_[3]");
$t->waitfor('/password: $/i');
}
$t->print("$_[1]");
$t->waitfor($t->prompt);

## Become superuser.
# $t->print("enable level 13");
# $t->waitfor('/password: $/i');
# $t->print(opera1ya);
$t->waitfor($t->prompt);
$t->print("conf terminal");
$t->waitfor($t->prompt);
$t->print(" $variable ");
$t->waitfor($t->prompt);
# $t->print(" $variable2 ");
# $t->waitfor($t->prompt);
$t->print("exit");
$t->waitfor($t->prompt);
$t->print("wr");
$t->waitfor($t->prompt);
$t->print("exit");
$t->close;
return 0;
}
__________________
startwav

http://e-hosting.startwave.com/img/banner.gif
Internet Nunca ha estado más cerca de Tí. e-Hosting Start Wave Media . Todo lo que necesitas para tener presencia en Internet.
Servicios de Registro Dominios / DNS / HOSTING / Y MUCHO MÁS...