perl script to telnet an eagle stp device
Hi,
I need to write a script that telnet to eagle STP device and run commands there.
When I try to telnet a eagle STP device from command prompt,
I am getting the below output :
[root@localhost tmp]# telnet hostname port
Trying hostname...
Connected to hostname hostname).
Escape character is '^]'.
I am not getting any prompt here to match in the perl script. We need to press control+a inorder to get the prompt.If we press control+a, it will give the below output
[root@localhost tmp]# telnet hostname port
Trying... Connected to hostname.
Escape character is '^]'.
>
Then we need to enter login:uid at this prompt
> login:uid=dumps
Then it prompts for a password
Enter password : password
then again we need to press control+a again to execute the commans.
> rtrv-dstn.
I am struck here , I am unable to pass control+a command after telnet command and also unable to match anything after the telnet command. because nothing is displayed, just cursor goes into the newline.
I wrote the script in the below way. But it is not working. Can ANY ONE HELP ME !!!!
#!/usr/bin/perl
use Net::Telnet;
my $host='hostname';
my $port='port';
my $telnet = new Net::Telnet(Host => $host, Port => $port, Timeout => 20)
or die "connect failed: $!";
$telnet->open($host);
print"Hi iii";
$telnet->waitfor('+$/i');');
print"Hello";
$telnet->print("^]");
$telnet->waitfor('/>$/i');
$telnet->print("login:uid=username");
$telnet->waitfor('/Enter Password :\s+$/i');
$telnet->print("password");
$telnet->waitfor('/>$/i');
@res1=$telnet->print("rtrv-dstn");
print"@res1";
Exit;
#####################
I have a linux server, where I need to press control+]. I am unable to do this also:
[root@testams0005 tmp]# telnet hostname port
Trying hostname...
Connected to hostname (hostname).
Escape character is '^]'.
^]
telnet> help
I wrote the same script for this also. But it is not working. Here also I am unable to match empty space or cursor also don't know how to pass control+].
#!/usr/bin/perl
use Net::Telnet;
my $host='hostname';
my $port='port';
my $telnet = new Net::Telnet(Host => $host, Port => $port, Timeout => 20)
or die "connect failed: $!";
$telnet->open($host);
print"Hi iii";
$telnet->print("\x01");
print"Hello";
$telnet->waitfor('/telnet >\');
@res1=$telnet->print("help");
print"@res1";
Exit;
I am getting the below error.
[root@testams0005 ~]# perl telnet.pl
Can't find string terminator "'" anywhere before EOF at telnet.pl line 11.
If I comment-out the line $telnet->waitfor('/telnet >\'); .Output is as follows :
[root@testams0005 ~]# perl telnet.pl
Hi iiiHello1
I am not getting the output of help command. I am just getting1 here.
Please help me if you can I working on this from 1 week and no luck.
Last edited by sam321; 08-22-2013 at 08:43 AM.
|