Solved

Telnet comand

Posted on 2002-05-07
6
357 Views
Last Modified: 2009-12-16
I need a script that connect to a server, make the login, run a command and print the output.

How to do it?

0
Comment
Question by:oleber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:sstouk
ID: 6994207
1) Install the Net::Telnet Module;

2) Try the following:

   use Net::Telnet ();
    $t = new Net::Telnet (Timeout => 15,
                          Prompt => '/bash\$ $/');
    $username = "";
    $passwd = "password";
    $t->open("systemIP");
    $t->login($username, $passwd);
    @lines = $t->cmd("dir");
    print @lines;
0
 
LVL 10

Author Comment

by:oleber
ID: 6994322
I have this error

'timed-out waiting for command prompt' in this line '$t->login($username, $passwd);'

I'm in windows

manual telnet works
0
 
LVL 8

Accepted Solution

by:
bebonham earned 75 total points
ID: 6994402
:

  use Net::Telnet ();
   $t = new Net::Telnet (Timeout => 15);
   $username = "";
   $passwd = "password";
   $t->open("systemIP");
   $t->login($username, $passwd);
   @lines = $t->cmd("dir");
   print @lines;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:oleber
ID: 6996502
The command that I execute takes many time. But it gives output every n seconds. Can I see that output in me script when is prodiced.

Thanks

0
 
LVL 8

Expert Comment

by:bebonham
ID: 6996602
no not as it is
0
 
LVL 6

Expert Comment

by:sstouk
ID: 6996838
I am sure it's something to do with the
(Prompt => '/bash\$ $/';)
Option.
The Script expects a specific prompt from the terminal server to make sure that the server has completed the output and is expecting for the command.
You will have to try different matching strings to make sure that there is a match of the prompt that script will expect.
This is custom to the terminal server.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question