# problem with sleep cmd in execution of cron...

**URL:** <https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721>\
**Category:** Shell Programming and Scripting\
**Created:** [January 31, 2012, 10:39am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721 "2012-01-31T10:39:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj424](https://community.unix.com/letter_avatar/manoj424/32/5_5575768a8748004e209b776fc1b2916d.png) [@manoj424](https://community.unix.com/u/manoj424)\
**Post date:** [January 31, 2012, 10:39am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/1 "2012-01-31T10:39:34Z")

</div>

I am scheduling a task at regular intervals at seconds acuracy using crond and sleep command . my data in crontab file is as below:-

> [@](#):
>
> 05 00 \* \* 0,4,5,6, sleep 45 && /usr/local/bin/set\_radio\_cron grp0 0 0 &

the above line is working fine when we are creating this crontab file before 00:05 min .  
But when we are creating the crontab file at 00:05min , unable to execute sleep cmd. But the next cmd "/usr/local/bin/set\_radio\_cron grp0 0 0" is able to execute.

please guide me in this. what may be the problem? where i have to modify to make it work?  
[as frm 00:05:00 to 00:05:59 has 1min duration and if i create the crontab file between this duration what will be the significance?]  
Thanks in advance..

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [January 31, 2012, 10:41am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/2 "2012-01-31T10:41:25Z")

</div>

What do you mean "unable to execute the sleep cmd"? What does it actually do?

---

<div class="post-metadata">

**Author:** ![manoj424](https://community.unix.com/letter_avatar/manoj424/32/5_5575768a8748004e209b776fc1b2916d.png) [@manoj424](https://community.unix.com/u/manoj424)\
**Post date:** [January 31, 2012, 11:06am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/3 "2012-01-31T11:06:20Z")

</div>

I mean that when the crontab file is created at 00:05:00 and executed at the same time. the " sleep 45 " command is not running and directly the second command is running. i.e "/usr/local/bin/set\_radio\_cron grp0 00 & "

I think now it is clear.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [January 31, 2012, 12:05pm UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/4 "2012-01-31T12:05:47Z")

</div>

> [@](#):
>
> [as frm 00:05:00 to 00:05:59 has 1min duration and if i create the crontab file between this duration what will be the significance?]

The significance is that the next time cron will look at the line you changed will be tomorrow at 00:05. To be safe you really needed to complete the change to crontab by 00:04 .

> [@](#):
>
> 05 00 \* \* 0,4,5,6, sleep 45 && /usr/local/bin/set\_radio\_cron grp0 0 0 &

The highlighted comma and ampersand are neither needed nor desirable.

---

<div class="post-metadata">

**Author:** ![manoj424](https://community.unix.com/letter_avatar/manoj424/32/5_5575768a8748004e209b776fc1b2916d.png) [@manoj424](https://community.unix.com/u/manoj424)\
**Post date:** [February 1, 2012, 12:44am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/5 "2012-02-01T00:44:21Z")

</div>

@ above

But actually when i am creating the crontab file in-between 00:05:00 to 00:05:59 the second command is being executed but the 1st command i.e sleep 45 is not running.

---

<div class="post-metadata">

**Author:** ![knight\_eon](https://community.unix.com/letter_avatar/knight_eon/32/5_5575768a8748004e209b776fc1b2916d.png) [@knight\_eon](https://community.unix.com/u/knight_eon)\
**Post date:** [February 1, 2012, 2:41am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/6 "2012-02-01T02:41:32Z")

</div>

> [@manoj424](#):
>
> @ above
> 
> But actually when i am creating the crontab file in-between 00:05:00 to 00:05:59 the second command is being executed but the 1st command i.e sleep 45 is not running.

I hope you have removed &

Secondly, are you sure that Sleep command did not get executed?

---

<div class="post-metadata">

**Author:** ![manoj424](https://community.unix.com/letter_avatar/manoj424/32/5_5575768a8748004e209b776fc1b2916d.png) [@manoj424](https://community.unix.com/u/manoj424)\
**Post date:** [February 1, 2012, 3:19am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/7 "2012-02-01T03:19:24Z")

</div>

> [@](#):
>
> I hope you have removed &

I didn' t get u.  
where I have to keep "&" .

---

<div class="post-metadata">

**Author:** ![knight\_eon](https://community.unix.com/letter_avatar/knight_eon/32/5_5575768a8748004e209b776fc1b2916d.png) [@knight\_eon](https://community.unix.com/u/knight_eon)\
**Post date:** [February 1, 2012, 4:04am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/8 "2012-02-01T04:04:12Z")

</div>

In your given Crontab Entry:

```nohighlight
05 00 * * 0,4,5,6, sleep 45 && /usr/local/bin/set_radio_cron grp0 0 0 & 

```

I can see there is & and one extra comma marked red there.

---

<div class="post-metadata">

**Author:** ![manoj424](https://community.unix.com/letter_avatar/manoj424/32/5_5575768a8748004e209b776fc1b2916d.png) [@manoj424](https://community.unix.com/u/manoj424)\
**Post date:** [February 16, 2012, 2:20am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/9 "2012-02-16T02:20:48Z")

</div>

> [@](#):
>
> 05 00 \* \* 0,4,5,6, sleep 45 && /usr/local/bin/set\_radio\_cron grp0 0 0 &

In above the sleep command is not working but the other command "/usr/local/bin/set\_radio\_cron grp0 0 0" is working for only below condition.  
-\> when present time is hr 00:05:12 sec , given time hr 00:05:00 sec

The above quoted command is working fine when :  
--\>when present time is hr 00:04:12 sec , given time hr 00:05:00 sec

please comment on above ...

---

<div class="post-metadata">

**Author:** ![hicksd8](https://community.unix.com/letter_avatar/hicksd8/32/5_5575768a8748004e209b776fc1b2916d.png) [@hicksd8](https://community.unix.com/u/hicksd8)\
**Post date:** [February 16, 2012, 5:09am UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/10 "2012-02-16T05:09:03Z")

</div>

If I understand this discussion properly, you are creating a crontab "on the fly", perhaps just one minute before it is timed to run? Why?

Crontabs are normally set up and left alone. The crontabs are read into memory when the kernel boots and the last modified date/time of the crontab is also remembered. "Periodically" the cron daemon will inspect the crontabs to see if anything has changed (by looking at the last modified date/time) and if it has, it will reload that table. Therefore, to my mind, there is no guarantee that a crontab created one minute before it is due to run will be executed one minute later. The cron daemon might not have seen the change by then.

Can any other forum members confirm what I've just said please.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [February 16, 2012, 5:23pm UTC](https://community.unix.com/t/problem-with-sleep-cmd-in-execution-of-cron/303721/11 "2012-02-16T17:23:05Z")

</div>

@manoj424  
The cron fires at 05:00 exactly, precisely, and to the millisecond.  
Any change you make after that time is too late.  
Get it?

I agree that you should also give cron a minute or more to see the change. This varies from system to system. The benchmark would be the second the "crontab -e" command finishes.  
There is no way that a change made after 05:00 to a cron scheduled at 05:00 would be actioned until the following day.
