Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to perform cron jobs every 5 minutes inside docker

I want to perform cron jobs every minute for feeds.sh and every 5 minutes for reminder.sh inside docker container. It was able to run every minutes for feeds.sh. However for reminder.sh, it cannot run every 5 minutes as it keep throwing the error /bin/ash: */5: not found inside the docker container.

The following code is shown as below :

FROM alpine:latest

# Install curlt 
RUN apk add --no-cache curl

# Copy Scripts to Docker Image
COPY reminders.sh /usr/local/bin/reminders.sh
COPY feeds.sh /usr/local/bin/feeds.sh


# Add the cron job
RUN echo ' *  *  *  *  * /usr/local/bin/feeds.sh &&  */5  *  *  *  *    /usr/local/bin/reminders.sh' > /etc/crontabs/root

# Run crond  -f for Foreground 
CMD ["/usr/sbin/crond", "-f"]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add it on a separate line.

When you use && with cron, it’s expecting multiple cron jobs to add for the same cron frequency.

eg.

0 * * * * a && b

Hence why it says "*/5 not found" because that’s the b above – it thinks it’s a cron script to run.

Add your */5 * * * * script on a separate line in its own command.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading