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

Greetings to everyone. I have a PERL script that needs one more piece of code to make it work properly. The code I need is to read or capture the output after running the 'Y' command. If the output is an error, then the next command that should be issued is a 'N' before continuing the loop. The problem with my script is that by not having this "error checking" code, the script times out and the telnet session is closed. When there is an error, the only other option to enter should be 'N'. Can anyone help?
#!/usr/bin/perl $user="username"; $pass="password"; $server="##.##.##.##"; use Net::Telnet; $t = new Net::Telnet; $t->open("$server"); $t->waitfor('/Enter User Name/'); $t->print("$user"); $t->waitfor('/Enter Password/'); $t->print("$pass"); $t->waitfor('/>/'); $t->print("servord"); open(LIST,"roamers.txt"); @numbers=<LIST>; foreach $number (@numbers) { $t->waitfor('/>/'); $t->print("deo"); $t->waitfor('/>/'); $t->print(""); $t->waitfor('/>/'); $t->print("$number"); $t->waitfor('/>/'); $t->print("cdw"); $t->waitfor('/>/'); $t->print("arw"); $t->waitfor('/>/'); $t->print("\$"); $t->waitfor('/>/'); $t->print("y"); # I need an "error checker" here. If giving the 'Y' command gives an # error output, then the following cmd should be 'N' # before continuing the loop. } close(LIST); $t->waitfor('/>/'); $t->print("quit all;logout");
Thanks for any help rendered.

Replies are listed 'Best First'.
Re: Reading a telnet command output
by laceytech (Pilgrim) on Dec 20, 2008 at 10:50 UTC
    It depends on the formatting of the error code.
    Use dump_log or dump_input to get an idea of the output.
    You could then use getline and test its content.
    See Net::Telnet
    Jim
      Thank you Jim, I appreciate your. I'll follow the link and take your advice. Being that this the first time I'm writing a Perl script, I'd appreciate if anyone can direct me to tutorials or examples of this dumplog and getline.