sonicscott9041 has asked for the wisdom of the Perl Monks concerning the following question:

I am fairly new to programming and very new to perl. I am having an issue with what I believe should be a simple task. Here is the code I use to log onto a box, navagate to where I need to go (inside a menu drive (text) program) and run a report. While this is working, the output I am getting is including the menus and such before the report runs. I want just the report. Any tips or suggestions, please?
#!/usr/bin/perl my ($t, $op1, $op2); use Net::Telnet (); $t = new Net::Telnet; $t->open("192.168.1.1"); ## Open data file for writing open (nvfile, '>testout.txt'); ## Wait for first prompt and respond with 'era'. $t->waitfor('/login:/'); $t->print("era"); ## Wait for login prompt. $t->waitfor('/USER ID/'); $t->print("ANYUSER"); $t->print("ANYPASS"); ## Navigate to the report screen and select report to run. $t->waitfor('/SELECTION/'); $t->print("77"); $t->print("1"); $t->print("4"); $t->print("6910"); $t->print("?"); $t->print("10"); ## Run report On-screen and capture to file $t->print("O"); ($op1) = $t->waitfor('/Press any key to continue/'); print nvfile $op1; $t->print("N"); ($op2) = $t->waitfor('/REPORT COMPLETE/'); print nvfile $op2; $t->print(""); $t->print("END"); ## Logoff $t->waitfor('/SELECTION/'); $t->print("88"); $t->print("Y"); exit;
Thanks in advance for any tips or suggestions.

Replies are listed 'Best First'.
Re: Net::Telnet / file question
by Illuminatus (Curate) on Jul 21, 2009 at 17:02 UTC
    What command actually runs the report? It seems like the session output before 'Press any key to continue' is what you are trying to avoid. If so, simply avoid printing $op1 to your results file.
      This is the area:
      $t->print("O"); ($op1) = $t->waitfor('/Press any key to continue/'); print nvfile $op1; $t->print("N"); ($op2) = $t->waitfor('/REPORT COMPLETE/'); print nvfile $op2;
      The print "O" (letter, not number) starts the report 'on-screen'. This prints the first screen of the report, then pauses with the 'Press any key to continue'. A human would basically look at the report one screen at a time (like the 'more' command on linux). However, by sending the print "N" command, it then runs the rest of report to the screen without any more of those 'Press any key to continue' messages. Thanks!
        Try doing a $t->waitfor for the prompt that you respond to with the "O" (letter, not number) input(just before the print). This will clear out the input stream up to the start of the report.