你有两个选择来获得这个.通常,cron与前一个作业实例是否仍在运行无关.
选项1:
在脚本的开头写一个锁文件,并在完成后将其删除.然后在脚本开头检查文件是否存在,如果是,则脚本结束而不做任何事情.例如,这可能是这样的:
# if the file exists (`-e`) end the script:
[ -e "/var/lock/myscript.pid" ] && exit
# if not create the file:
touch /var/lock/myscript.pid
...
# do whatever the script does.
# if condition
sleep 300 # wait 5 min
...
# remove the file when the script finishes:
rm /var/lock/myscript.pid
选项2:
这也很有用.它被称为run-one.从联机帮助页:
run-one – run just one instance at a time of some command and unique
set of arguments (useful for cronjobs,eg)
然后cronjob可能如下所示:
* * * * * /usr/bin/run-one /path/to/myscript