allow only one instance of a script running – use lock file with “noclobber” option
#!/bin/shLOCKFILE="/tmp/mutex-script.lock"## noclobber prevents that an existing file gets overwritten when using the ">" operatorif/bin/sh-c"set -o noclobber; echo \"$$\" > \"$LOCKFILE\""; thenecho"aquired $LOCKFILE"trap"rm -f \"$LOCKFILE\"; echo \"released $LOCKFILE\"; exit \$?" INT TERM EXIT KILL
elseecho"could not aquire $LOCKFILE"exit1fiecho"DO STUFF"sleep20echo"DONE"
allow only one instance of a script running – use lock directory
#!/bin/shLOCKDIR="/tmp/mutex-script.lock"## "mkdir" is atomicifmkdir"$LOCKDIR"; thenecho"aquired $LOCKDIR"trap"rmdir \"$LOCKDIR\"; echo \"released $LOCKDIR\"; exit \$?" INT TERM EXIT KILL
elseecho"could not aquire $LOCKDIR"exit1fiecho"DO STUFF"sleep20echo"DONE"
Cookies helfen bei der Bereitstellung von Inhalten. Durch die Nutzung dieser Seiten erklären Sie sich damit einverstanden, dass Cookies auf Ihrem Rechner gespeichert werden. Weitere Information
commands-shell-snippets.txt · Zuletzt geändert: 2018/02/04 17:36 von alex