#!/bin/bash
DEFAULT_LOCK="/tmp/.somelock"
lock() {
LOCK=${1:-$DEFAULT_LOCK}
lockfile -r 0 $LOCK 1>/dev/null 2>&1
return $?
}
unlock() {
LOCK=${1:-$DEFAULT_LOCK}
[ -f $LOCK ] && rm -f $LOCK
return $?
}
После можно писать:
После можно писать:
lock && echo "lock ok test"
lock || echo "lock not ok test"
unlock && echo "unlock ok test"
unlock || echo "unlock not ok test"