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 *

  +  26  =  36

Skynin cache:
Array ( [cache mode] => capture [requestKey] => 112aefe4d69436a94ffd25da18d1d11d51c.sc [skycache_disable_capture] => false )