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

In reply to Re^2: Using Expect module in Net::Telnet by msk_0984
in thread Using Expect module in Net::Telnet by msk_0984

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.