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>
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.