I was experimenting with Expect.pm and ran into a problem.

I was trying to write a script that would reboot an SSL server that has it's cert protected with a passphrase.
(Not normally a good idea I know, but nothing very sensitive on this particular machine though.)

The script starts the server fine (According to the output of apachectl anyway) but it appears that the server is immediately dispatched. I just get a defunct apachectl process.

I tried using the soft_close method but it doesn't make any difference. I tried leaving the script around sleeping thinking Expect was killing it on exit but even then, it dies instantaneously (the soft_close was after the sleep). Is this normal behavior? Is there some concept I'm missing? I don't understand this behavior and I'm guessing it shouldn't be doing this. I don't see any errors in any of the logs. I've tried turning Expect's debugging on and don't see any indication of an error either.

Here's the code...
#!/usr/bin/perl use Expect; my $apache = "/usr/local/apache-ssl/bin/apachectl"; $command = Expect->spawn($apache, 'startssl') or die "Couldn't start program: $!\n"; # prevent the program's output from being shown on STDOUT # $command->log_stdout(0); # wait 10 seconds for pass phrase unless ($command->expect(20, -re => "Enter pass phrase ?")) { # timed out } # send passphrase print $command "NotARealPassPhrase\r"; ## wait 10 seconds for confirmation of server start. unless ($command->expect(10, -re => "Ok: Pass Phrase Dialog successful +.")) { die "Passphrase excepted!\n"; } ## wait 10 seconds for confirmation of server start. Otherwise, die unless ($command->expect(10, -re => "startssl: httpd started")) { die "SSL Didn't start!\n"; } # program will terminate by itself, finish with $command->soft_close();


-Lee

"To be civilized is to deny one's nature."

In reply to Trouble starting Daemon with Expect.pm by shotgunefx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.