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"]
CodePudding user response:
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.
CodePudding user response:
Updated Docker File to run both every minute and every 5 minutes
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' >> /etc/crontabs/root
RUN echo ' */5 * * * * /usr/local/bin/reminders.sh' >> /etc/crontabs/root
# Run crond -f for Foreground
CMD ["/usr/sbin/crond", "-f"]