How to disable run multiple cron jobs on different EC2 instances

Task: Disable run multiple cron jobs on different EC2 instances with common EFS directory

Implementation

Run bash script as a cron job task and add your command(s) after # Command(s) row:

!/bin/sh -xv
# Avoid run multiple cron jobs on different instances…
if [ ! -f /mount/efs/cronjob.lock ]; then
  # Create lock file
  echo "cronjob" > /mount/efs/cronjob.lock
  # Command(s)…
  echo "Test"

  # Delete lockfile
  rm /mount/efs/cronjob.lock
fi

Done.

Leave a Reply

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




Enter Captcha Here :