Q . Run cron job only if it isn't already running.

Brad Johnson. asked, Jan 02 ' 2016


How can I detect that cron job is already runnning so do not execute the script till the previous one stop the execution.

  • linux
  • bash
  • cron
  • cronjob

1 Answers

You can do this with help of below example :

just write a shell script in the shell file and set the shell script in crontab like below example :


if ps -ef | grep -v grep | grep cron.php ; then
    echo "Running"
    php /home/user/public/cron/cron.php >> /dev/null


and set the shell script in crontab like :

$ sh /home/user/public/cron/cron.sh


Leave a Ansewer