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);

In reply to Perl script to read 500 entries from a .txt file by user786

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.