in reply to Check if file is written by other process
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:
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.# 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;
|
|---|