my @output; eval { # Get the timeout value from the properties file $properties_file = $properties_directory."/".$properties_file; %values_hash = load_properties($properties_file); $script_timeout = $values_hash{'script.timeout'}; # Prepare the lockfile my $lock_file_directory = ""; $lock_file = "emc_backups.lck"; $lock_file_directory = abs_path($0); $lock_file_directory =~ s/(.*)\/.*/$1/; $lock_file = $lock_file_directory."/".$lock_file; # Start logging my $log = $values_hash{'logfile'}; startLog($log); # If script is already running, then exit. If not, create a lock file. verify_lockfile($lock_file, $script_timeout); # Kill the script if it runs longer than the timeout value (in seconds) local $SIG{ALRM} = sub { die "Timeout\n" }; alarm $script_timeout; @output = main(); alarm 0; }; if ($@) { # Script timed out # Delete aborted copy, if any if ($currentBackupCopying) { purge_backups($currentBackupCopying); } print LOGFILE "ERROR: Backup timed out - ".localtime()."\n"; # Delete Lock File unlink($lock_file); } else { # Script ran successfully print LOGFILE "Backup finished - ".localtime()."\n"; # Delete Lock File unlink($lock_file); }