Adding use strict; use warnings; would have pointed this out to you btw.
Having worked quite a bit with Juniper devices myself, I used Net::Telnet::Cisco but had to customize the "prompt" setting in order to get ->cmd() to work as expected. If you are using that module and didn't set the appropriate "prompt" setting, then ->cmd() will hang indefinitely while waiting for a Cisco command prompt, which is a little different.
I know I'm guessing a lot here, but I hope it helps. FYI, here's how I do it with MX, EX and SRX series -- seems to work pretty well:
@lines = $session->cmd( String => 'show version | no-more', Prompt => '/\n\S+\>/');
Putting it all together, try this:
use strict; use warnings; # Open your $rh and authenticate here # ... open(my $fh, "+>>default_ve.txt") || die "Couldn't open file: $!"; my @lines = $rh->cmd(String => 'show version | no-more', Prompt => '/\ +n\S+\>/'); foreach my $line (@lines) { print $fh $line; } close $fh; # Close $rh or do more stuff here # ...
Finally, note the use of "| no-more" to safeguard against output longer than your (virtual) terminal size which would cause an interactive prompt. Use it always, just to be safe.
If you're not using a Juniper device, read the stuff about the loop and disregard everything else :o)
Time flies when you don't know what you're doing
In reply to Re: File operations
by FloydATC
in thread File operations
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |