ARCHIVE_KEEPNDAYS=30
BACKUP_RUNEVERYNTHDAY=1
-function upperme {
- echo $(basename $0) | tr '[:lower:]' '[:upper:]'
-}
+_UPPERME=$(echo $(basename $0) | tr '[:lower:]' '[:upper:]')
function scottyinfo {
- echo $(upperme): $@
+ echo $_UPPERME: $@
}
function scottyerror {
- echo $(upperme): $@ >&2
+ echo $_UPPERME: $@ >&2
}
function ssh255 {
done
}
-function prepare {
- scottyinfo "Preparing for sync."
+function deleteLock {
+ if ! rmdir /var/lock/$(basename $0); then
+ scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!"
+ fi
}
function cleanup_abort {
kill $(jobs -p)
fi
+ deleteLock
+
exit
}
scottyinfo "No prepare function was defined."
}
+function cleanup_normal {
+ cleanup
+ deleteLock
+}
+
function printhelp {
cat <<EOF
Usage: $(basename $0) [OPTION]...
prepare
scottysync
- trap cleanup EXIT
+ trap cleanup_normal EXIT
exit 0
}
-exec 200>/var/run/$(basename $0).pid
-if ! flock -n 200; then
+if ! mkdir /var/lock/$(basename $0); then
scottyerror "Another instance of $(basename $0) is still running!"
exit 1
+else
+ trap deleteLock EXIT
fi
-echo $$ 1>&200