$filepath = "host.conf"; $counter=0; if(open(FILE,$filepath)) { $inputline=; while($inputline ne "") { chop($inputline); if($inputline !~ /#/) { if( @array = split(/:/,$inputline) ) { #print @array; $host = $array[1]; $user = $array[2]; $pass = $array[3]; push @threads, threads->create(\&sshcon, $host, $user, $pass); } #if2 } #if1 $inputline=; } #while while( my $thread = shift @threads ) { $thread->join(); print " Thread $counter exiting \n"; $counter++; } } else { die " File doesn't exists " } sub sshcon { my($h,$u,$p)=(shift,shift,shift); print " Host Info : $h,$u,$p \n"; my $ssh2 = Net::SSH2->new(); #$ssh2->debug(1); $ssh2->connect($h) or die " Cannot connect to $h "; print "Connected to host $h \n"; die "can't authenticate" unless $ssh2->auth(username => $u,password=>$p); # ,interact=>1); #print "Username/Password is correct\n"; $chan2 = $ssh2->channel; #print " Channel opened successfully \n"; die "Can't create a shell on channel " unless $chan2->shell; die " Cannot set blocking field " unless $chan2->blocking(0); print $chan2 "hostname \n"; print "Error --> " , $chan2->error() , "\n" ; print "LINE : $_" while <$chan2>; print $chan2 "who \n"; print "LINE : $_" while <$chan2>; $ssh2->disconnect(); } #### Connected to host 192.168.1.92 Error --> 0 LINE : Sun Microsystems Inc. SunOS 5.9 Generic May 2002 LINE : indialab92 LINE : SunOS indialab92 5.9 Generic_118558-34 sun4u sparc SUNW,Sun-Blade-1000 Thread 0 exiting