LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2013, 08:42 AM   #1
sam321
LQ Newbie
 
Registered: Aug 2013
Posts: 1

Rep: Reputation: Disabled
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.
 
Old 08-26-2013, 01:43 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
please use [code]your code[/code] to keep formatting
you may try the expect module
looks like there is an error in line 9: $telnet->waitfor('+$/i');');
please fix it
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Perl/Expect script connecting to a server using telnet. kenji Programming 2 08-31-2012 02:29 AM
Telnet to usb device on interface usb0 (and find IP of device) chickenlinux Linux - Networking 4 10-18-2009 11:18 AM
telnet -> use contrl-D to exit using python telnet script athreyavc Programming 5 07-06-2009 11:17 PM
Running Telnet in a script, want to save Telnet output, howtodothis??? anil3 Linux - Software 2 03-08-2006 04:01 PM
How is it possible to login as root with Perl script and used telnet.pm manu0573 Linux - Software 1 07-27-2005 05:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration