24   Linux

crontab 保证只有一个任务在执行

1,脚本自带重复执行的判断


#!/bin/bash

exec_cmd='/usr/bin/php'
full_file='/root/test/crontab_shell_main.php'
check_exist=`ps -ef |grep $full_file | grep -v grep | wc -l`
if [[ $check_exist -eq 0 ]];then
	echo "no"
	$exec_cmd $full_file
else
	echo "yes"
fi


2,在 crontab 添加锁文件机制

*/5 * * * * /usr/bin/flock -n /tmp/ms.lockfile /usr/bin/php /root/test/crontab_shell_main.php



Leave a Reply

Your email address will not be published. Required fields are marked *