Hi! I've been spending 2 days on trying to find a thread and SSH module that works together, but to no avail. You're my last hope.
I have a few hundred nodes running on GPRS links that I need to do some work on once in a while. Since GPRS are so damned slow, my ordinary approach of connecting one by one is not viable, thus I began looking on threading. However, when I run the example code posted below, I randomly run into this errormessage:
perl: ath.c:193: _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed.
4 of 5 times it exit early with that message, 1 in 5 it complete the job.
I've tried Net::SSH::Expect as well as Thread::Pool, Threads & Thread::Queue and any combination of those to no avail. Net::SSH::Expect behaved even worse.
I'm running this on perl 5.12.4 on Ubuntu 11.10. Please help me save the little hair I have left by pointing me in the direction of a possible solution. ;-)#!/usr/bin/perl use Thread::Pool; use Net::SSH2; use strict; open (MYINPUTELEMENTS, "./list.txt"); my $pool = Thread::Pool->new( { workers => 10, do => \&worker_parse, }); while (my $element = <MYINPUTELEMENTS>) { if ($element =~ /(\d+)(\.\d+){3}/) { $pool->job($element); } } close (MYINPUTELEMENTS); $pool->shutdown; sub worker_parse { my $inIP = $_[0]; chomp($inIP); my $ssh2 = Net::SSH2->new(); if ($ssh2->connect($inIP)) { if ($ssh2->auth_password('user','pass')) { my $gssChannel = $ssh2->channel(); $gssChannel->exec('ls -l / | wc -l'); my $gssData; my $gssLen = $gssChannel->read($gssData,8192); chomp($gssData); print "gss: $gssData - "; $gssChannel->close; my $lcsChannel = $ssh2->channel(); $lcsChannel->exec('ls -l /etc | wc -l'); my $lcs2Data; my $lcs2Len = $lcsChannel->read($lcs2Data,8192); chomp($lcs2Data); print "lcs2: $lcs2Data\n"; $lcsChannel->close; $ssh2->disconnect; } else { print "Authentication Failed\n"; } } else { print "Connection Failed\n"; } }
In reply to Net::SSH2 not thread safe? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |