【发布时间】:2014-08-06 18:56:18
【问题描述】:
我正在尝试运行一个 perl 脚本,该脚本读取一个包含 500 个条目的文本文件,一次读取一个条目并发送一个命令。
命令是server hostname,其中主机名的值是文本文件中的主机名列表。
我是编程新手,据我了解,我们需要打开包含主机名的文件并读取它open (ENABLE, "<hostanmes.txt") || die "could not open output file";
使用 for 循环读取其中的 512 个主机名for($i=1; $i<=512; $i++)
但我不确定如何将此文件连接到命令server hostname
程序不完整。我很震惊,不太确定。有人可以帮我解决这个问题吗?
#!/usr/bin/perl
## Library import
use Net::SSH::Expect;
use strict;
use warnings;
use autodie;
print "\n [INFO] script Execution Started \n";
my $ssh = Net::SSH::Expect->new (host => "ip addr",
password=> 'pwd',
user => 'username',
raw_pty => 1);
my $login_output = $ssh->login();
print "\n [INFO] add host rules \n";
open (ENABLE, "<hostanmes.txt") || die "could not open output file";
for($i=1; $i<=512; $i++)
{
my $cfg = $ssh->exec("config");
my $cmd = $ssh->exec("server www.google.com");
my $cmd = $ssh->exec("exit");
}
close(ENABLE);
【问题讨论】:
标签: perl perl-module