Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

problem in perl telnet module

by Shivageeta (Initiate)
on Jan 25, 2005 at 11:33 UTC ( #424829=perlquestion: print w/replies, xml ) Need Help??

Shivageeta has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am Shivageeta S. Choodi, working for Novell, Bangalore in system testing group.
I have used Perl for the test automation. I am facing a problem in telnet module of Perl. The problem details are as follows and the script (around 10 lines) is also attached.
Problem description:
Test machine: Running the script from a SLES 8 machine
The script : is attached. It does telnet to a machine (hard coded in the script), and a create a file /my-Perl after the successful telnet.
Problem: If the host specified in the script is SUSE/SLES machine, the script hangs. But the same script works fine if I change the host to some other Unix/Linux hosts for example RH Linux/Solaris. I am also able to manually telnet to the SUSE/SLES boxes (for which the script is hanging during the telnet operation).
Perl telnet module: Net-Telnet-3.03
The Code:
#!/usr/bin/perl #use Time::Format; BEGIN { push(@INC,'/usr/lib/perl5/site_perl/5.8.0/URI/'); } require ""; #Initialise telnet $telnet = new Net::Telnet->new( Timeout=>20,Prompt => '/[\$%#>] $/'); die &Log_Message("Can't open telnet session to the remote host") unles +s $telnet; #Telnet and login to a remote machine $telnet->open("systst-lnx-15"); $telnet->login("root","novell"); print "Logged into the system \n"; #After a successful telnet create the file /my-perl at the remote host +. $telnet->cmd("touch /my-perl"); $telnet->close;

Can you please let me know is there any problem with the perl telnet module which have installed?
I request you to help me in solving this problem (i.e. the script should be able successfully telnet to a SUSE/SLES machine and create a file).

With Regards,

Replies are listed 'Best First'.
Re: problem in perl telnet module
by BrentDax (Hermit) on Jan 25, 2005 at 12:05 UTC

    It would really help if we knew exactly when it's hanging--is it during open? login? cmd?

    Have you tried using input_log, as the documentation recommends? If it's hanging during cmd, that could indicate that the Prompt regex is incorrect; input_log may help you debug that.

    In the mean time, I'd like to point out a couple other problems:

    • You aren't bringing the module in the way it's intended to be. Remove the BEGIN block and the require, and replace it with a simple use Net::Telnet;.
    • You don't need new twice in new Net::­Telne­t->ne­w--either new Net::Telnet or Net::Telnet->new is fine. Use whichever you think looks better. (Frankly, I'm not sure why the two-new version even works.)

    --Brent Dax
    There is no sig.

      $ perl -MO=Deparse,-p,-q -e '$telnet = new Net::Telnet->new( Timeout=> +20,Prompt => "/[\$%#>] $/");' ($telnet = 'Net::Telnet'->new->new('Timeout', 20, 'Prompt', ('/[$%#>] +' . $/)));

      Net::Telnet's new has the called-with-ref-use-its-class incantation (way back in IO::Handle::new). But you're right, it's unnecessary.

Re: problem in perl telnet module
by simon.proctor (Vicar) on Jan 25, 2005 at 12:50 UTC
    In the absence of other info (as already commented on) are you sure the machine is running Telnet. My install of Suse only uses SSH.

      Actually Shivageeta did say "I am also able to manually telnet to the SUSE/SLES boxes". I would think if telnetd was not running on the machine, it would result in a simple failure to connect (so Net::Telnet->new returns undef and this is caught as a fatal error).

Re: problem in perl telnet module
by Anonymous Monk on Jan 25, 2005 at 11:41 UTC
    Where does the script "hang"? Does it succesfully connect to the box? Does it get a prompt? Can it login? Does it execute the command (perhaps not succesfully?) Does it fail to close the connection? Please, explain where it "hangs".
Re: problem in perl telnet module
by muntfish (Chaplain) on Jan 25, 2005 at 16:59 UTC

    I do hope that's not really your root password that you've posted there...

    I've added a request to consider editing it out of the node.

Re: problem in perl telnet module
by edan (Curate) on Jan 25, 2005 at 12:00 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://424829]
Approved by theroninwins
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-05-23 18:25 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.