Keep It Simple, Stupid | |
PerlMonks |
Re: File operationsby FloydATC (Deacon) |
on Nov 20, 2015 at 14:31 UTC ( [id://1148239]=note: print w/replies, xml ) | Need Help?? |
Assuming $rh is connected to the appropriate host and you have successfully authenticated (to what looks like a Juniper device?), the main problem here seems to be your while(){} loop which will never end but (assuming ->cmd() ever exists) will keep executing the same command over and over, assigning the output to a variable that immediately goes out of lexical scope.
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:
Putting it all together, try this:
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)
-- FloydATC
Time flies when you don't know what you're doing
In Section
Seekers of Perl Wisdom
|
|