I am running a test script where in a loop of 800, two crontab scripts create new crontab in a duration of 5 seconds.


while [ "$counter" -lt 800 ]; do
    crontab -r
    create_crontab_1.sh >> cr_log.log
    sleep 5;
    create_crontab_2.sh>> cr_log.log
    (( counter++ ))


CRONLINE="*/2 * * * * /scratch/test1.sh >/dev/null 2>&1"
( crontab -l 2>/dev/null ; echo "${CRONLINE}" ) | crontab -

crontab cron_file.txt

cron_file.txt ->
* * * * * sleep 2; /scratch/test3.sh >/dev/null 2>&1
* * * * * sleep 3; /scratch/test4.sh >/dev/null 2>&1

/var/log/cron log:

crond[25583]: (user_name) RELOAD (/var/spool/cron/)
CROND[29339]: (root) CMD (sleep 3; /abc/test3.sh >/dev/null 2>&1)
CROND[29340]: (root) CMD (sleep 2; /abc/test4.sh >/dev/null 2>&1)
crontab[29345]: (user_name) LIST ()
CROND[29353]: (user_name) CMD (/abc/test1.sh >/dev/null 2>&1)
crontab[29365]: (user_name) REPLACE ()

Even when crontab with test1.sh gets overwritten in 5 seconds, why does test1.sh comes in cron log, and can be seen getting invoked every 2 mins (as it is scheduled to run every 2 mins) ?? Also does it have anything to do with CPU clock?

  • 1
    create_crontab_1.sh and create_crontab_2.sh does not appear to be shell scripts. The loop removes the crontab (with -r) and then it runs these text files. You should see errors, yes?
    – Kusalananda
    Commented Mar 22, 2017 at 10:17
  • /var/log/cron output Commented Mar 22, 2017 at 10:21
  • The log you've included shows a LIST entry towards the end. I'm assuming this is done by you running crontab -l on the command line as there is no such command in the script. There are no timestamps in the log, so it hard to tell if the log is relevant at all.
    – Kusalananda
    Commented Mar 22, 2017 at 10:35

1 Answer 1


If we look at the commands inside your loop, and reorder them a bit, the repeating part is this:

while ... do
    create_crontab_2.sh >> cr_log.log
    (( counter++ ))
    crontab -r
    create_crontab_1.sh >> cr_log.log
    sleep 5;

What create_crontab_2.sh does to edit the crontab is undone by the following crontab -r. Only what is set in the crontab by create_crontab_1.sh is there during the sleep. As changing the crontab is likely to be fast, it's not likely that cron is going to see the rules set by create_crontab_2.sh pretty much at all.

  • I have modified the loop logic to following: Commented Mar 23, 2017 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .