Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BusyBox cron container example
FROM gliderlabs/alpine:3.3
COPY myawesomescript /bin/myawesomescript
COPY root /var/spool/cron/crontabs/root
RUN chmod +x /bin/myawesomescript
CMD crond -l 2 -f
#!/bin/sh
echo "Hi Andy" >> /dev/stdout
* * * * * /bin/myawesomescript
@desprit

This comment has been minimized.

Copy link

desprit commented Sep 29, 2016

It is very hard to find the meaning on crond arguments. Could you please tell what do -l 2 -f mean?

@jaimewyant

This comment has been minimized.

Copy link

jaimewyant commented Sep 30, 2016

Try crond --help:

/ # crond --help
BusyBox v1.24.2 (2016-06-22 17:51:28 GMT) multi-call binary.

Usage: crond -fbS -l N -d N -L LOGFILE -c DIR

    -f  Foreground
    -b  Background (default)
    -S  Log to syslog (default)
    -l N    Set log level. Most verbose:0, default:8
    -d N    Set log level, log to stderr
    -L FILE Log to FILE
    -c DIR  Cron dir. Default:/var/spool/cron/crontabs
@Niondir

This comment has been minimized.

Copy link

Niondir commented Oct 24, 2016

crond[5]: wakeup dt=10
crond[5]: wakeup dt=50
crond[5]: file root:
crond[5]:  line /bin/myawesomescript
crond[5]:  job: 0 /bin/myawesomescript
crond[15]: child running /bin/sh
crond[5]: USER root pid  15 cmd /bin/myawesomescript
/bin/sh: /bin/myawesomescript: not found

Any idea? When I enter the container the script exists. How can I debug this further?

@Niondir

This comment has been minimized.

Copy link

Niondir commented Oct 24, 2016

Wow I had #!bin/sh instead of #!/bin/sh in my script ...

@eduncan911

This comment has been minimized.

Copy link

eduncan911 commented Apr 2, 2017

BusyBox crond from a stock AlpineLinux docker image has the pre-configured cron schedules:

bash-4.3# cat /var/spool/cron/crontabs/root
# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
*/15    *       *       *       *       run-parts /etc/periodic/15min
0       *       *       *       *       run-parts /etc/periodic/hourly
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly

NOTE: following the directions in the original post above will override these schedules, effectively disabling it with your custom root cron config file.

But you don't have to do that...

If one of the above schedules works for you, you can simply place your script in one of these directories as needed:

FROM alpine:3.5
COPY myawesomescript1 /etc/periodic/15min/myawesomescript1
COPY myawesomescript2 /etc/periodic/15min/myawesomescript2
COPY myawesomescript3 /etc/periodic/hourly/myawesomescript3
CMD crond -l 2 -f

It is important to know that your script cannot be suffixed with any extension name. E.g. no "." period can exist. It cannot end in .sh. That was the gotcha I ran into this weekend.

@mfurlend

This comment has been minimized.

Copy link

mfurlend commented Mar 1, 2018

@eduncan911

E.g. no "." period can exist. It cannot end in .sh

Thanks for the tip! I was getting pretty frustrated.

@shadiakiki1986

This comment has been minimized.

Copy link

shadiakiki1986 commented Jun 27, 2018

+1 for cannot end in .sh

@ofekp

This comment has been minimized.

Copy link

ofekp commented Jan 7, 2019

Another +1 for cannot end in .sh

@mskyttner

This comment has been minimized.

Copy link

mskyttner commented May 17, 2019

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.