Hi monks,
I am writing a script to telnet into a cisco switch and run mutiple commands e.g sh top,sh traffic etc.
My question is how do i use one object referenc to run multiple commands.
I want the flexibility of reading the commands from a config file.
here is what i have got so far.
$cs is the net::telnet object reference
# Execute the command open( FI ,"< $ciscomm_conf") || die ("Cannot find configuration file c +ontaing commands to be run at $ciscomm_conf:$!"); while(<FI>) { my $ciscommand = $_; if(( $ciscommand !~ m/\#/ ) && ($ciscommand !~ m/^\s+$/)) { @cmd_output = $cs->cmd( String => $ciscommand,Timeout =>60); if (!@cmd_output) { push(@cmd_output," command failed or returned null input +\n"); } } } cose FI;
I even tried reading the file in an array and doing a
foreach $tmp (@cms) { @cmd_output = $cs->cmd( String => $ciscommand,Timeout =>60); }

unfortunately in both cases the @cmd_output array is empty.
If i run only one command without a "while" or "for" the same code works.
Any suggestions
Regards <chimni>

In reply to Net::Telnet::Cisco usage by chimni

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.