I have a requirement to do a script for gather some data from one db and formatting according to a requirement, this should run by a scheduled cron job. but there should not be parallel runs. (If one process is running, then other should not start).

Help me to do this in bash scripting.


You can use lock file. At script start check if lock file is already exist, if so exit, if not continue. When create lock file. execute your script. And before exit remove lock file. something like this:

if [ - f lock ] ; then
exit 1
touch lock
your code
rm lock
  • With few changes, I could complete the work.. Thanks for great help ! – Ishara Kularatna Jun 4 '18 at 13:43

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