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.
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.