Just putting this here because it helped me out today.  How do you ensure (on #linux ) that only one instance of a script is running, without race conditions or having to clean up lock files?  Simple:


    if ! flock -n -x 0
        echo "$$ cannot get flock"
        exit 0
    echo "$$ start"
    sleep 10 # for testing.  put the real task here
    echo "$$ end"
) < $0
Shared publiclyView activity