in reply to Re^2: Cron Jobs That Run For Too Long
in thread Cron Jobs That Run For Too Long
But wait, it gets better again!
You know how you can have that nifty __DATA__ block at the end of your script? It turns out you can lock that too :)
I've used this a number of times and it works just great.
#!/usr/bin/perl
use strict;
use Fcntl 'LOCK_EX', 'LOCK_NB';
unless ( flock DATA, LOCK_EX | LOCK_NB ) {
print STDERR "Found duplicate script run. Stopping\n";
exit(0);
}
...
1;
### DO NOT REMOVE THE FOLLOWING LINES ###
__DATA__
This exists to allow the locking code at the beginning of the file to work.
DO NOT REMOVE THESE LINES!
You know how you can have that nifty __DATA__ block at the end of your script? It turns out you can lock that too :)
I've used this a number of times and it works just great.
#!/usr/bin/perl
use strict;
use Fcntl 'LOCK_EX', 'LOCK_NB';
unless ( flock DATA, LOCK_EX | LOCK_NB ) {
print STDERR "Found duplicate script run. Stopping\n";
exit(0);
}
...
1;
### DO NOT REMOVE THE FOLLOWING LINES ###
__DATA__
This exists to allow the locking code at the beginning of the file to work.
DO NOT REMOVE THESE LINES!
In Section
Seekers of Perl Wisdom