如果所有用户的脚本都相同,则可以使用一种
lockfile方法。如果您获得了锁,请继续执行其他操作,并显示一条消息并退出。
举个例子:
[Terminal #1] $ lockfile -r 0 /tmp/the.lock[Terminal #1] $[Terminal #2] $ lockfile -r 0 /tmp/the.lock[Terminal #2] lockfile: Sorry, giving up on "/tmp/the.lock"[Terminal #1] $ rm -f /tmp/the.lock[Terminal #1] $[Terminal #2] $ lockfile -r 0 /tmp/the.lock[Terminal #2] $
/tmp/the.lock获得脚本后,您的脚本将是唯一可以执行的脚本。完成后,只需取下锁。在脚本形式下,它可能类似于:
#!/bin/bashlockfile -r 0 /tmp/the.lock || exit 1# Do stuff hererm -f /tmp/the.lock



