Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a cron job that runs every X mins and that I would like to have a way to "signal" it not to do anything if needed.
Is there a standard way for this? The only idea I had is to check some directory for the existence of a file and if it is there exit. Does this approach make sense? Are there any other approaches?

share|improve this question

When a cronjob is set correctly, it always runs. You must "signal" your script or program, not cron itself.

In your case, you can check existence of files easily. Making a wrapper script wrapper.sh:


if [ -e /path/to/file1 ] && [ -e /path/to/file2 ]
    exit 1

# Your script goes here

Then you must configure your cronjob to run wrapper.sh. It will check that your files exist, and if so it will exit, else run your script as normal.

share|improve this answer
But why should I put the code in the wrapper and not inside the script? – Jim Apr 8 '14 at 18:47
You don't actually need a wrapper (or to edit the script), you can just put the file test in the crontab itself—cron runs it through a shell. – derobert Apr 8 '14 at 18:50
@Jim and derobert: It depends on your implementation, each have its own advantages. If you use an wrapper script, you can also run an binary program, or you don't need to change cronjob entry when you change your program. – cuonglm Apr 8 '14 at 18:55
I like the way @Gnouc does this because it doesn't clutter the crontab, and it leaves whatever script you want this behavior to apply to untouched. Also, if you decide later to add scripts, you don't have to rerun the wrapper, just add your script to it. – David Wilkins Apr 8 '14 at 19:18
1) But if I add the check inside the script how does it clutter the crontab? 2) What is the 2 files check? – Jim Apr 8 '14 at 19:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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