Overlap of group of scripts

oraclescripting

I have a group of scripts set to run in a certain order, but sometimes I find the group running long and overlapping into the next group run. Is there a way to prevent that?

group.sh:
script1.sh &
wait
script2.sh &
wait
script3.sh

group.sh is still running (perhaps on script3.sh) when group.sh kicks off for the next run.

Best Answer

I'm assuming this is a Unix question, and you're not using OEM Cloud Control etc. I tend to do this by using a temporary file (with a known name) that indicates whether the script is still running or not. For example:

#!/bin/bash

if [ -f /tmp/groupisrunning ] ; then  
  # do not execute if the process is already running. This is controlled by the 
  # the existence of the above file

  echo "Already running" 

else

  touch /tmp/groupisrunning

   # DO YOUR WORK BELOW THIS LINE, eg: 
  script1.sh
  script2.sh
  script3.sh
  rm -f /tmp/groupisrunning
fi   

There are other ways of doing this (ps parsing, using a service), but I find this simple & reliable.