473,372 Members | 814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Perl code- using the Telnet module for remote login to a windows XP machine


I have written a perl script using the Telnet module. I need to remotely login in from one windows XP machine to another XP machine.

But i get errors which i can't figure out the reason.
Please someone help me its very very urgent.

here is my code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Net::Telnet;
  6. my $telnet = new Net::Telnet (Timeout=>10);
  7. $telnet->open($ip_addr)or print "can't open the server";
  9. $telnet->waitfor('/:/');
  11. $telnet->print($login);
  12. $telnet->waitfor('/:/');
  14. $telnet->print($password);
  15. $telnet->waitfor('/:/');
  17. $error=$telnet->errmsg;
  20. $telnet->cmd("mkdir ABC");
  21. $error=$telnet->errmsg;
  23. $telnet->close;
In this code i trying to login to a remote machine using telnet. and the task is to create a directory on the telnet server.(dir ABC).

i get an error:
command timed-out at D:\Perl_RemoteLogin\RemoteLogin_Telnet.pl line 27

Please can any one tell me whats going wrong in the code.
Aug 20 '08 #1
6 5478
410 Expert 256MB
Try giving a timeout value for the commands that you pass.
Expand|Select|Wrap|Line Numbers
  1. $cmd="mkdir ABC";
  2. $telnet->cmd( String => $cmd, Timeout =>20,);
Aug 21 '08 #2
Hi nithinpes

This too didn't work. can you tell me where am i going wrong. i guess the matching is going wrong
Aug 21 '08 #3
410 Expert 256MB
Hi nithinpes

This too didn't work. can you tell me where am i going wrong. i guess the matching is going wrong
I am not sure what is wrong then..May be someone else would know.
Aug 22 '08 #4
You'll probably find its failing on the command promt..its waiting for a certain prompt and not getting it. I've changed it so its just looking for : see if that works. What is your promt?
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.       use strict;
  3.       use Net::Telnet;
  5.       my $telnet = new Net::Telnet (Timeout=>10);
  6.       $telnet->open($ip_addr)or print "can't open the server";
  7.       $telnet->waitfor(': $/i');
  8.       $telnet->print($login);
  9.       $telnet->waitfor(': $/i');
  10.       $telnet->print($password);
  11.       $telnet->waitfor(': $/i');
  12.       $telnet->cmd("mkdir ABC");
  13.       $telnet->close;
Sep 9 '08 #5
3,509 Expert Mod 2GB
First, you really need to use code tags around the code you post to the forums. I have added them to your post so edit it and see how they are used.

As for your code, you don't want to do a print after the "open", you want to do a die and print the error that was produced, like so:

Expand|Select|Wrap|Line Numbers
  1. $telnet->open($ip_addr) or die "Can't open the connection:  $!";

The $! will contain the error message from the connection attempt and give you a clue as to why it is failing. Always use die when performing an action like opening a file or a connection or such and print the error. That way, your debugging is a little easier.


Sep 9 '08 #6
4,059 Expert 2GB
The code as posted looks like it should not even compile because $login has never been declared properly.
Sep 9 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the...
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
by: Paul Porcelli | last post by:
Hi folks, I have a perl one-liner embedded in a ksh script. perl -pi.bak -e "s/val/otherval/" inputfile I'd like to check the return code to know if the substitution was successful. If I...
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in...
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
by: Shawn Milo | last post by:
I'm new to Python and fairly experienced in Perl, although that experience is limited to the things I use daily. I wrote the same script in both Perl and Python, and the output is identical. The...
by: pchaw | last post by:
I try to develop a demo, which client in Perl will try to call the web services I wrote in C#. I've no knowledge in Perl, but as I refer to online forum, I try to follow their example but return no...
by: Corey G. | last post by:
If Perl 6 ever does get on its feet and get released, how does it compare to Python 3000? Is Perl 6 more like Java now with Parrot? I just want to make sure that Python is staying competitive. ...
by: Palindrom | last post by:
Hi everyone ! I'd like to apologize in advance for my bad english, it's not my mother tongue... My girlfriend (who is a newbie in Python, but knows Perl quite well) asked me this morning why...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.