runif for lockutil

This commit is contained in:
2023-09-08 08:37:10 +03:00
parent a189d6dc6f
commit a21d62dfce

View File

@@ -1,12 +1,15 @@
#!/bin/bash
VERSION=230908.0
_help() {
echo '
Usage: lock-util {lock-file} [-v] [command] [args]
Commands:
create
exist ( return 0 if lock exists )
old [age in seconds] ( return 0 if file younger than [args] seconds or file not present )
old [age in seconds] ( return 0 if file older than [args] seconds or file not present )
runif [age in seconds] ( old + create, if file not exist, or older than [arg], then touch file and return 0, else 1 )
remove
-v as first argument sets very verbose mode
@@ -80,5 +83,17 @@ _remove() {
exit $ec
}
[[ $COMMAND = "runif" ]] && {
[[ -z "$ARG" ]] && _help && echo "MISSING ARGUMENT" | $BOXES && exit 1
VERBOSE=$VERBOSE "$0" "$LOCKFILE" old "$ARG"
ec=$?
[[ $ec -eq 0 ]] && {
_exist && _remove
VERBOSE=$VERBOSE "$0" "$LOCKFILE" create
ec=$?
}
exit $ec
}
echo Command not recognized
_help