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

I was asked by someone here at work if there was a way that I could write a script that would automate a backup job on a Windows box (has perl on it).

But one of the steps involvs backup up some files, and then calling another script (perl) which actually does the backup. Now, both of these steps will produce some kind of output normally, such as "xx files copied" and "restored successfully".

Is there a way that I can watch or look for this output, and then move onto the next step only when I see this? Sometimes, the times vary as far as how long it takes.

Thanks in advance!

Replies are listed 'Best First'.
Re: How to monitor/look for output?
by ikegami (Patriarch) on Jun 02, 2009 at 16:17 UTC
    It would be more reliable to set the exit code appropriately.
    # special.pl my $success = 1; ... if (...) { $success = 0; } ... exit $success ? 0 : 1;

    Then all you need is

    perl special.pl && perl backup.pl

    Note that if special.pl dies for any reason, the exit code will be set to something nonzero, so even unexpected failures will also prevent backup.pl from executing.

Re: How to monitor/look for output?
by apl (Monsignor) on Jun 02, 2009 at 16:16 UTC
    Write your log to disk, and tail -f your log.

    Revised: Ignore. I thought the OP was asking for a manual way to check his log... Sleep beckons...

Re: How to monitor/look for output?
by elTriberium (Friar) on Jun 02, 2009 at 23:40 UTC
    Assuming that you cannot / are not allowed to modify the original scripts, why don't you just run the first script in backticks and collect it's output? Then, based on the output you can either run the second script or do something else.
      Yeah, that's how I have it setup currently. For that though, should I use a "foreach" loop to cycle through the lines of the output and look for certain output, or what do you think would be the best way to go about that?
        The correct solution depends strongly on what the script is outputting. I would note that backticks return a scalar, so a foreach would be kinda pointless without splitting or some such. Likely the best choice is to think about what is different about successful vs. failing executions and craft a regular expression to check the output string whole hog. We could help with that if you gave us sample outputs for success and failures.