DEV Community

Discussion on: Ensuring that a shell script runs exactly once

Collapse
 
rivetmichael profile image
Michael R
flock -n 99
RC=$?
if [ "$RC" != 0 ]; then
    # Send message and exit
    echo "Already running script. Try again after sometime"
    exit 1
fi

This snippet does not work for me, I never fall into the condition RC different from 0 so I never see "Already running script" message, although look had correctly been acquired, any idea why ?