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

I have a perl script that does several things then executes the following code:

my $expectREF = Expect->new (); $expectREF->debug (2); $expectREF->raw_pty (0); $expectREF->log_user (0); $expectREF->spawn ($command); $expectREF->expect (undef, "Password: "); $expectREF->send ("$pword\n"); $expectREF->interact (\*STDIN, 'EOF');

It runs fine without using crontab.

When crontab is used, expect will exit before $command finishes running but $command continues to run in the background. What do I need to do so that expect will not exit before $command finishes?

Replies are listed 'Best First'.
Re: Expect doesn't wait for an EOF with crontab
by almut (Canon) on Feb 27, 2010 at 23:59 UTC

    My suspicion is that your usage of STDIN is the issue here. Some versions of cron open it to /dev/null, others don't supply a valid fd 0 at all. In any case, who or what is supposed to close it in order for Expect to detect an EOF at the appropriate time?

    Maybe you can make Expect wait for some msg/string in the command's output which would indicate that $command has finished.  Just an idea...