Correct way of setting up CRON job in dockertemplate file command line

Hello,

I am trying to add two cron job tasks to my dockerfile. If I add one (1 line) everything works. If I want to add more I sometimes encounter problems. What is the correct way to add multiple cron jobs with balena when deploying? One should check every 5 minutes, the other one run once a day at 2:00 am.

Thanks!

#CRON JOB
RUN (crontab -l ; echo “*/5 * * * * /usr/src/app/cron_check.sh”) | sort - | uniq - | crontab -
RUN (crontab -l ; echo “0 2 * * * /usr/src/app/cron_restart.sh”) | sort - | uniq - | crontab -

Hi @rquant, I personally would do it with a script, like this one in balenaDash: https://github.com/balena-io-projects/balena-dash/blob/master/scheduler/scripts/start.sh

I’m wondering if when you’re adding two there’s some kind of race condition happening that’s avoided by using a script; the above has always worked reliably in my experience.

1 Like

Thank you, I will try it!