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";
|