I was trying to connect to remote system by using Net::SSH::Perl module . I have installed all the required modules for this module to work and tried my hand on writing a small script by embeding it in multi threads. Here is the code
When I execute the above code with only two threads, the CPU is going upto 100% and system is getting hanged. My ram size is appriximately 4GB. I have no problem with a single thread or when executed without threads.#!/usr/bin/perl use Net::SSH::Perl; use threads; $filepath="/tmp/Perl/host.conf"; if(open(FILE, $filepath)) { $inputline=<FILE>; while($inputline ne "") { chomp($inputline); if($inputline !~ /#/) { if( @array = split(/:/,$inputline) ) { $host = $array[1]; $user = $array[2]; $pass = $array[3]; print "\n\n\n ------ CHECK1 $user $host $pass +\n\n\n\n\n "; push @threads, threads->create(\&method, $host +, $user, $pass); } #if2 } #if1 $inputline=<FILE>; } #while while ( my $thread = shift @threads ) { $thread->join ; print " Thread [ $host ] Ending ... \n"; } } else { die " File doesn't exists " } sub method { my($hst,$usr,$pas)=(shift,shift,shift); &thrds($hst, $usr, $pas); } sub thrds { my($h,$u,$p)=(shift,shift,shift); $ssh = Net::SSH::Perl->new($h,debug=>'true'); $ssh->login($u,$p); my($stdout, $stderr, $exit) = $ssh->cmd('hostname'); my($stdout, $stderr, $exit) = $ssh->cmd('ls -l'); print $stdout; $ssh->close(); }
Did I mis-configured any thing. Please help me.
Thanks in advance,
Srinivas.
In reply to Problem with threads in Net::SSH:Perl by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |