Is this a valid way of check that no two executions of a script run at the same time? Or is it a race condition?
#!/bin/bash
if test "$(pgrep -f 'something-unique-about-this-script' | wc -l)" -ne 1
then
echo "Too many instances"
exit 1
fi
Is this a valid way of check that no two executions of a script run at the same time? Or is it a race condition?
#!/bin/bash
if test "$(pgrep -f 'something-unique-about-this-script' | wc -l)" -ne 1
then
echo "Too many instances"
exit 1
fi
mkdir
is an atomic command, so I like
if ! mkdir ~/.app_lock_dir; then
echo already running >&2
exit 1
fi
# schedule the dir for removal
trap 'rm ~/.app_lock_dir' EXIT