From aad0734411ecf750bf2233dba6cffb333da50d68 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 11 Feb 2015 21:13:59 +0100 Subject: [PATCH] Use flock for locking. --- backmeupscotty | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/backmeupscotty b/backmeupscotty index be1ce20..44e9c54 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -125,12 +125,6 @@ function scottysync { done } -function deleteLock { - if ! rmdir /tmp/$(basename $0).lock; then - scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!" - fi -} - function prepare { scottyinfo "Preparing for sync." } @@ -145,8 +139,6 @@ function cleanup_abort { kill $(jobs -p) fi - deleteLock - exit } @@ -158,11 +150,6 @@ function prepare { scottyinfo "No prepare function was defined." } -function cleanup_normal { - cleanup - deleteLock -} - function printhelp { cat </var/run/$(basename $0).pid +if ! flock -n 200; then scottyerror "Another instance of $(basename $0) is still running!" exit 1 -else - trap deleteLock EXIT fi +echo $$ 1>&200 -- 2.39.5