I want my script run singleton,I refer to flock,the script runs well except debian 7.11.
When I runs in docker debian 7.11,it gives the following error: flock: ./single.sh Text file busy
I download the debian 9,it runs well,If this can not fixed,I have to try another way to make the script run singleton.
I wonder if there is a way to fix this.
#!/bin/bash
# singleton exec
[ "${EDR_FLOCKER}" != "$0" ] && exec env EDR_FLOCKER="$0" flock -eno "$0" "$0" "$@" || :
echo "Helloworld"
sleep 20
I found the reason why this fail,the argument of flock can not be the script self. Modify the script as below everything works fine.
#!/bin/bash
# singleton exec
[ "${EDR_FLOCKER}" != "$0" ] && exec env EDR_FLOCKER="$0" flock -eno "$0.lock" "$0" "$@" || :
echo "Helloworld"
sleep 20