Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Using Expect module in Net::Telnet

by msk_0984 (Friar)
on Jun 28, 2008 at 13:12 UTC ( [id://694511]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Expect module in Net::Telnet
in thread Using Expect module in Net::Telnet

Hey Monks,

Another thing where I have got stuck. Please advice me atleast in this case and need you sincere suggestion to move ahead and perform the tasks.

As you must have seen the above logic to login using normal user and switch to different user and perform operations. I need to enhance this more by adding threads to the existing code, when did the same I am facing problems. I feel Net::SSH::Expect module is not supporting the threads facility, may because as we use exec()/send() function.

foreach $line ( @info ) { next if ( $line =~ /^#/ or $line eq "" ); ($ip, $host, $user, $passwd, $suser, $spasswd ) = spli +t (/:/, $line ); print " INFO ==> $ip , $host, $user, $passwd, $suser, +$spasswd \n\n"; ### - Creation of SSH object here itself -- ### my $ssh = Net::SSH::Expect->new(host=>$ip, user=>$user +, password=>$passwd, raw_pty=>1 ) or die " Cannot Open "; $login_check=$ssh->login(); my $hs = $ssh->exec('hostname'); print " HOST of $host --> $hs \n"; #&nsecon($ip, $user, $passwd, $suser, $spasswd); ## &nsecon( $ssh ); push @threads, threads->create(\&nsecon, $ssh ); } while( my $thread = shift @threads ) { $thread->join(); print " Thread $counter exiting \n"; $counter++; } sub nsecon() { #($ip, $user, $passwd, $suser, $spasswd) = ( shift, shift,shif +t,shift,shift); $ssh = shift; #print "In Thread => $ip, $user, $passwd, $suser, $spasswd \n" +; ### -- Commented this part as threads were exiting -- ### ### So created the ssh object in the main thread and passing it to the + function ### ### my $ssh = Net::SSH::Expect->new(host=>$ip, #user=>$user, #password=>$passwd, #raw_pty=>1 ) or die " Cannot +Open "; ### ) or die " Cannot Open "; #$login_check=$ssh->login(); print "LOGIN for $ip -- $login_check \n"; my $who = $ssh->send('ls'); #print "\n OUT1 $who \n"; while ( defined ($line = $ssh->read_line()) ) { print " Line => $line " . "\n"; } my $ls = $ssh->send('who am i '); #print "\n OUT2 - $ls \n"; while ( defined ($line = $ssh->read_line()) ) { print " Line => $line " . "\n"; } }
When I am executing this script only the first thread returns the output and all the next threads are connecting to the systems and not returning nor the commands are getting executed.

Please help me out in this case.

Thanks In Advance.

Sushil Kumar

Replies are listed 'Best First'.
Re^3: Using Expect module in Net::Telnet
by Anonymous Monk on Jun 22, 2009 at 17:21 UTC
    I am trying to connect to my QNX m/c from the host PC, which haswindows xp.I want to kill two processes which run on my QNX PC from my host PC.For this purpose I am using a perl script which uses Net::Telnet....Although the perl script seems to be proper and according to the guidelines given by ppl below, my perl script is not entering the login name.It opens the command prompt and stops there.Which version of perl supports Net::Telnet .Please help me out...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://694511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found