# for the script
#!/usr/bin/perl -w
use CGI;
use Fcntl qw(O_WRONLY O_CREAT O_EXCL);
my $q = new CGI;
my $lockfile = '/tmp/lock';
if (sysopen(FH, $lockfile, O_WRONLY | O_CREAT | O_EXCL)) {
# sysopen will only work if lockfile does not exist
# exec the script and wait for it to complete using bacticks or exec
`your_update_script`;
close FH;
unlink $lockfile or error("Can't unlink lockfile $lockfile $!");
print $q->redirect('http://page_to_display_after_update');
}
else {
error("Update already in progress!
");
exit;
}
sub error { print $q->header, shift; }