I'm trying to run a perl script which reads a text file that contains say 500 entries, read one entry at a time and send a command.
The command is server hostname
where the value of hostname is the list of hostnames in the text file.
I'm new to programming,As per my understanding we need to open the file that contains the host name and read it open (ENABLE, "<hostanmes.txt") || die "could not open output file";
use a for loop to read the 512 host names in it for($i=1; $i<=512; $i++)
But I'm not sure how to connect this file to the command server hostname
The program is incomplete.I'm struck and not really sure.Can somebody please help me with this ?
#!/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);