Что не так с скриптом perl?

Помогите довести до ума скрипт
use Net::Telnet;
use IO::File;

open my ($ip) = (IPlist, "iplist" or die "can't open iplist: $!");

my ($username) = 'admin';
my ($passwd) = 'admin';
my ($ena)='enable';
my ($conf)='conf t';
my ($command1)='hostname R2D2';
my ($command2)='exit';
my ($command3)='wr mem';
	
 $t = new Net::Telnet (Timeout => 10, Telnetmode => 1,  Input_Log => "infile.log", Output_log => "output.log",);
           $t->open("$lines");
           $t->waitfor('/login:$/i');
           $t->print($username);
           $t->waitfor('/Password:$/i');
           $t->print($passwd);
		   $t->print ("$ena");
		   $t->print ("$conf");
		   $t->print("$command1");
		   $t->print("$command2");
		   $t->print("$command3");
		   $t->print("$command2");


При запуске скрипта пишет problem connecting to "" port 23.
Т.е. скрипт не извлекает строку с адресом из iplist.txt

Для цикла, как я понял, нужно будет использовать нечто вроде:
while (@ lines = "<IPlist>") 
 {
           $t->open("$lines");
           $t->waitfor('/login:$/i');
           $t->print($username);
           $t->waitfor('/Password:$/i');
           $t->print($passwd);
		   $t->print ("$ena");
		   $t->print ("$conf");
		   $t->print("$command1");
		   $t->print("$command2");
		   $t->print("$command3");
		   $t->print("$command2");
}
close ( IPlist );

но тогда скрипт просто виснет.
P.S. Команды написаны для примера.
  • Вопрос задан
  • 2460 просмотров
Решения вопроса 1
@krypt3r
open my ($ip) = (IPlist, "iplist" or die "can't open iplist: $!");
my ($username) = 'admin';
while (@ lines = "<IPlist>")

Ну и бред вы пишете.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы