In regards to the above I later realized you don't even need a second script - using a PID file, your script could kill its previous run when run a second time. Here's a script to demonstrate the idea: Run it once, it will do its "work" for 10 seconds, and if you run it a second time during that time, the second process will kill the first, and do its "work". Since it's just a proof-of-concept this has no handling in the case of being run more than twice, and it's full of potential race conditions (although you did say the invocations will be 24 hours apart).

use warnings; use strict; # PROOF OF CONCEPT ONLY # - NO race condition protection or file locking # - method for killing not entirely reliable and can loop endlessly # (see e.g. source of Time::Limit for ideas) my $PIDFILE = "foo.pid"; # FIXME: use absolute path $SIG{TERM} = sub { print "exit by signal\n"; exit 0; }; if (-e $PIDFILE) { my $oldpid = do { open my $ifh, '<', $PIDFILE or die $!; <$ifh> }; while ( kill(0,$oldpid) ) { # is proc running & can we signal it? kill 'TERM', $oldpid; sleep 1; } } END { unlink $PIDFILE } open my $ofh, '>', $PIDFILE or die $!; print $ofh $$; close $ofh; sleep 10; # do heavy work print "normal exit\n";

In reply to Re^4: Self terminating a script after a specified time by Anonymous Monk
in thread Self terminating a script after a specified time by shardservant

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.