Operating System - HP-UX
1823058 Members
3183 Online
109645 Solutions
New Discussion юеВ

Perl & Telnet module regex

 
Ratzie
Super Advisor

Perl & Telnet module regex

I have a script that needs to enter some control char. and I dont think I am parsing my acadmin@medusa$ telnet host1 2008
Trying...
Connected to host1.
Escape character is '^]'.
(need to hit cntr B)

I@12:01:48 LOG ON


ENTER LOGON ID: ID1 (need to hit control c)
ENTER PASSWORD: (need to hit control c)
R@12:03:37 SIOO008 JOB 0020 11/06/06 SWITCHDS1
ID1 LOGGED ON TERMINAL 20 AT 12:03:37 ON 11/06/06


(Here the cursor is at a blank line, and I hit CNRTL B to get the next prompt of:
I@12:12:57




Here is my script:
#!/usr/bin/perl
use Net::Telnet;

$t = new Net::Telnet (timeout => 10,
Errmode => 'die',
Host => 'host1',
Port => '2008');
$t->open ();
$t->waitfor('/^Escape character is/');
$t->print ('^B');
$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 ('PASSWORD123^C');

*how can I monitor at what step I am failing at?

When I run it complains about not match the Escape character...:
pattern match read eof at telnet.pl line 9
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: Perl & Telnet module regex

Hi:

This seems like a follow-on to your earlier post:

https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1073695

I suggest that you use the notation provided therein.

Regards!

...JRF...

Ratzie
Super Advisor

Re: Perl & Telnet module regex

I have used the previous post to enter the control characters in, but my script does not even get that far. I still cacs out at the Escape character is...
James R. Ferguson
Acclaimed Contributor

Re: Perl & Telnet module regex

Hi:

I think that part of your problem is that your writes (print) are not producing a newline.

Either explicitly add it ("\n") or add the '-l' switch to your interpreter line:

#!/usr/bin/perl -l

Regards!

...JRF...
Heironimus
Honored Contributor

Re: Perl & Telnet module regex

Part of the trouble may also be that you're waiting for the remote server to send "Escape character is". That's probably displayed by your local telnet client, not by the remote server. Net::Telnet probably won't ever see that string.
Ratzie
Super Advisor

Re: Perl & Telnet module regex

Maybe my search needs to look for something else...
Because when I log in manually, the propmt is actually two lines lower after the Escape character...

Connected to host1.
Escape character is '^]'.


#the prompt is actually here(need to hit cntr B)
I@12:01:48 LOG ON (cntr c)

So I tried...
$t->open ();
$t->waitfor('/^$/');
$t->print ("\cB");

I still get an error...
pattern match read eof at telnet.pl line 11
James R. Ferguson
Acclaimed Contributor

Re: Perl & Telnet module regex

Hi (again):

It apppears that the newline is appended by default. Perhaps this helps you a bit:

http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm

For tracing purposes, you could add 'warn' calls:

...
waitfor( ... ) or warn "can't read...";
...

Regards!

...JRF...
Ratzie
Super Advisor

Re: Perl & Telnet module regex

Well, I have tried but could not get the parsing to recognise all the nuances of switch replied.
Did it quicker with expect that was called by perl

Appreciate all the help though!