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.


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:


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" 


  touch /tmp/groupisrunning

  rm -f /tmp/groupisrunning

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

  • I have seen that used for backups by a vendor and it came back to bite us. The server crashed during the seasonal time change when a backup was running. When it was rebooted all the following attempts to backup the server stopped as the temp file was still there. – kevinsky Apr 18 at 15:26
  • 100% in agreement – Philᵀᴹ Apr 18 at 15:27
  • @kevinsky - well, no solution is perfect, and that's the most elegant solution that I've ever seen +1. It's not too much of a stretch to assume that sysadmins will have documented procedures and checks to run in the event of a crash which can easily check for the existence of such "signal" files. – Vérace Apr 18 at 16:19
  • @Vérace Yes, you would assume that a database support vendor that offers services around the world 24 hours a day would have documented procedures to cover off a server crash. Management was unpleasantly surprised that in addition to backups not taking place there was also no provision to alert on no backups.... – kevinsky Apr 18 at 16:42
  • Care to hint as to who this vendor migth be? – Vérace Apr 18 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.