Forking and SSH connections

J

jrpfinch

Dear gurus,

Please could somebody give me a hint as to why this script at the
bottom of this post does not work when I remove the nofork=>1 from
line 19? When I remove it (i.e. the scheduler becomes a forking
scheduler), checkMsMessages works the first time, but the second time
I get an error:

bash-2.05# /opt/perl5.8.8/bin/perl distill2.pl
Scheduling started...
stdout is beatbox
Bad packet length 1879469963 at /opt/perl5.8.8/lib/site_perl/5.8.8/Net/
SSH/Perl/Packet.pm line 175

Ultimately I would like the scheduler to be forking because it will
have multiple entries all happening at similar times. Any tips on how
to achieve this would be appreciated. Setting up an SSH login every
time checkMsMessages is called would be expensive, so I would like to
avoid this.

Many thanks

Jon

use strict;
use warnings;
use Net::SSH::perl;
use Schedule::Cron;
main();

sub main
{
my $cron = new Schedule::Cron(\&dispatchDefault);
my $conn;

$conn = Net::SSH::perl -> new ("10.xxx.xxx.xxx", protocol => 2);
$conn->login("user","password");
$cron->add_entry("* * * * * 30", { 'subroutine' =>
\&checkMsMessages,
'arguments' =>
[$conn]});

print "Scheduling started...\n";
$cron->run(nofork=>1);
}

sub checkMsMessages
{
my $currentConnRef = $_[0];
my ($stdout, $stderr, $exit);

($stdout, $stderr, $exit) =
$currentConnRef->cmd
('echo beatbox');
chomp ($stdout);
print "stdout is $stdout\n";
}
sub dispatchDefault
{
print "ID: ",shift,"\n";
print "Args: ","@_","\n";
die "Functionshould never be called."
}
__END__
 
X

xhoster

jrpfinch said:
Dear gurus,

Please could somebody give me a hint as to why this script at the
bottom of this post does not work when I remove the nofork=>1 from
line 19? When I remove it (i.e. the scheduler becomes a forking
scheduler), checkMsMessages works the first time, but the second time
I get an error:

Complex protocols often don't work across forks, so this doesn't surprise
me. One possible problem is that I think most SSH ciphers use CBC, which
means encrypted text of one block is used as part of the encryption of the
next block. Since forked sibling processes don't share this state
information, they can't work properly.

bash-2.05# /opt/perl5.8.8/bin/perl distill2.pl
Scheduling started...
stdout is beatbox
Bad packet length 1879469963 at /opt/perl5.8.8/lib/site_perl/5.8.8/Net/
SSH/Perl/Packet.pm line 175

Ultimately I would like the scheduler to be forking because it will
have multiple entries all happening at similar times. Any tips on how
to achieve this would be appreciated. Setting up an SSH login every
time checkMsMessages is called would be expensive, so I would like to
avoid this.

It *might* be possible to hack away at SSH to get it to work, but I think a
better avenue would be either to just accept the cost of setting up SSH
login each time, or change the cron to invoke your routine 1/10 (or
whatever) as often and then have the process itself loop 10 times on the
same connection before closing it.

Xho
 
J

jrpfinch

Thanks xho,

I'm going to carry on using nofork until it falls over. If it does,
then i'll try out your "1/10 as often" suggestion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top