i5513 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

At Expect-1.21 (debian unstable version) and at Expect-1.32 (Gábor Szabó version), I can read:
My script fails from time to time ... try using $exp->soft_close()
And later:
This will wait 15 seconds for a process
I have search at the code, and the delay is on Expect.pm:
$end_time = time() + 15;
   while ( $end_time > time() ) {
Well, my question is.. I have configured ssh ControlMaster to yes. Playing with Expect, the first connection will delay such 15 seconds:
system ('ssh -O exit localhost 2> /dev/null;'); use Expect; print Expect::version(); $su=new Expect; $su->log_user(1); $su->spawn ("ssh localhost echo aa"); $su->soft_close(); # this step hang 15 seconds # $su->expect(undef); exit 0;
If I try it with a not ssh master initial conection it works:
system ('ssh -O exit localhost 2> /dev/null; ssh -M localhost -fN 2> /dev/null'); use Expect; $su=new Expect; $su->log_user(1); $su->spawn ("ssh localhost echo aa"); $su->soft_close(); # this step now will not take more than 1 second #$su->expect(undef); exit 0;

At the first moment I thought it was a ssh issue, but it run fine without Expect Perl module

Do you know what is happen there (why perl 'system' call detect the finish of ssh commands but Expect not)?

PD: To setup this example, you need pubkey auth on localhost (ssh-keygen + ssh-copy-id + ssh-agent (search about ssh passwordless if you did not know about)) Pd2: updated to clarify the question

Replies are listed 'Best First'.
Re: ssh controlmaster and expect perl module
by salva (Canon) on Dec 18, 2015 at 06:36 UTC
    Instead of reinventing the wheel, you could use Net::OpenSSH.

      Hello salva,

      Your module have the reply to my question. Using "-o ControlPersist=no" fix the script which fails.

      I see you customize some ssh options which not obey to ~/.ssh/config when use Net::Openssh. But I will give it a try. Sure I can reimplement my scripts with your module.

      I cannot remember why I discarded this module when I started to write autologin script. Sure that it was a bad decision

      Thank you!