Others have already mentioned using a wrapper if you can not alter the script itself. If the script is being run from a cron job (which it sounds like it is) then you can do something like the following for a wrapper:

# NOTE! this is only a general outline of the concept, # and is NOT actual working code. # wrapper.pl use strict; use warnings; my $flagfile = '/path/to/flag_file.txt'; # you might want to test and see if this exists first, indicating a po +ssible # failure in code elsewhere. # # also, you might write the PID of the current process into the file s +o you # can check later if the process is still running if the file is prese +nt. open my $flag, '>', $flagfile; close $flag; my @script_params = ( '-opt1 yes', '-opt2 no', ); my $script = '/path/to/script.pl'; # use the multi-arg version of system to avoid lot's of gotchas. RTF(i +ne)M. system( $script, @script_params ); rm $flagfile; exit;
You would then run the wrapper in the cron job instead of the script itself. Now all you have to do is see if the flag file exists, and if it does, you know the main script has not finished processing yet.

You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

In reply to Re: Check if file is written by other process by boftx
in thread Check if file is written by other process by techman2006

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.