Thursday, November 5, 2015

Keep a scripted job from overlapping on itself

seems simple but have you ever had a scheduled job run long for any number of reasons and wished you could easily prevent it?

to prevent this you can easily touch/timestamp a file when the job starts, then have your script look for that file before it proceeds with the job.

 -i use this snippet in some backup scripts and it works quite well.

KEEP IT SIMPLE STUPID

#!/bin/bash

if [ -f $JOB_FLAG_DIR/.kiss.job.in_progress ]
    then
  /bin/mail -s "JOB OVERLAP $job_name -$host_name $script_name" $critical_mail < $JOB_FLAG_DIR/.kiss.job.in_progress
    exit 1555
    else
echo $job started `date +%Y%m%d.%H:%M:%S` > $JOB_FLAG_DIR/.kiss.job.in_progress
ps ax | grep $script_name | head -n 1 >> $JOB_FLAG_DIR/.kiss.job.in_progress
fi

No comments:

Post a Comment