Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::Telnet and control characters

Status
Not open for further replies.

lhradowy

IS-IT--Management
Aug 2, 2002
6
CA
I need to create a perl script that logs into a switch thru a terminal server, and then sends a control B to enter a command, the a control C to send the command.
All lower case characters are what I need to enter before and after the commands.
what is in red is the actual prompts
what is in yellow is what I need to do to send command

#########

telnet switch1 2008
Trying...
Connected to switch1
Escape character is '^]'.

Cntr b
I@11:25:56 LOG ON cntr c

Cntrl b
ENTER LOGON ID: ID1 ctrl c
ENTER PASSWORD: XXXX ctrl c
R@11:26:19 SIOO008 JOB 0071 09/15/05 SWITCHDS1
ID1 LOGGED ON TERMINAL 20 AT 11:26:19 ON 09/15/05


Ctrl b
I@11:26:57 LOG OFF ctrl c
OK JOB 0072 ASSIGNED

R@11:27:04 SIOO009 JOB 0072 09/15/05 SWITCHDS1
ID1 LOGGED OFF TERMINAL 20 AT 11:27:03 ON 09/15/05

telnet> QUIT

#######
my script
#!/usr/bin/perl -w
use Net::Telnet;

$t = new Net::Telnet (timeout => 10,
Errmode => 'die',
Host => 'switch1',
Port => '2008');
$t->open ();
$t->waitfor('/^Escape character is/');
$t->print ('\cB'); #did try with the actual ^B as well
$t->waitfor('/^I@[0-9]{2}:[0-9]{2}:[0-9]{2}/');
$t->print ('LOG ON^C');
$t->waitfor('/ENTER LOGON ID: /');
$t->print ('ID1^C');
$t->waitfor('/ENTER PASSWORD: /');
$t->print ('XXXX^C');

I can not get this far...
If I can figure out the correct syntax for login then I can enter the rest for the other commands.
 
Not sure if it'll work, Have you tried $t->cmd("^B");
 
I believe your problem is the fact that you are not interpolating the control sequence:

lhradowy said:
$t->print ('\cB'); #did try with the actual ^B as well

What you want here is actually "\cB". You are currently passing a literal three character string instead of a the control code Control-B.

Disclaimer: I have no experience with Net::Telnet
 
Maybe
Code:
my $CTRLC = "\cC";
my $CTRLB = "\cB";

$t->print("LOG ON$CTRLC");
might work? Put the values in variables. makes them easier to maintain, and read.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top