aptible / supercronic

Cron for containers
MIT License
1.84k stars 112 forks source link

Hi, is it a bug..? Only the last cron is being executed. #122

Closed EOM closed 1 year ago

EOM commented 1 year ago

Test file ok crontab in docker :

bash-5.1# supercronic -test crontab

INFO[2023-03-30T21:40:59Z] read crontab: crontab
INFO[2023-03-30T21:40:59Z] crontab is valid

RUN supercronic in docker online In 3 crons only the last one it is always executed. Why is this happening? Is it a bug or my mistake?

File crontab

APP='CRON_APPS'
HOME='/home/nobody'
BIN_CAKE='vendors/bin/cake'
PATH_APP='/var/www/html/app'

CAKECMD=TangoAPISync.get_deudas_cheques_de_los_clientes_r_e_s_t
0 */30 0-06 * * * * /bin/bash -c 'cd $PATH_APP && ../$BIN_CAKE $CAKECMD' > ${HOME}/${APP}_${CAKECMD}.txt 2>&1

CAKECMD=PedidosYaApiSync.get_orderns_and_push_all_heart_beat_pedidos_ya_api_sync
0 * 00-05,12-23 * * * * /bin/bash -c 'cd $PATH_APP && ../$BIN_CAKE $CAKECMD' > ${HOME}/${APP}_${CAKECMD}.txt 2>&1

CAKECMD=MagentoApiSync.get_pedidos_comandas_magento_r_e_s_t
0 * 00-05,12-23 * * * * /bin/bash -c 'cd $PATH_APP && ../$BIN_CAKE $CAKECMD' > ${HOME}/${APP}_${CAKECMD}.txt 2>&1

CAKECMD=RappiApiSync.get_orderns_rappi_api_sync
0 * 00-05,12-23 * * * * /bin/bash -c 'cd $PATH_APP && ../$BIN_CAKE $CAKECMD' > ${HOME}/${APP}_${CAKECMD}.txt 2>&1
EOM commented 1 year ago

Hi el problem is for ${VARS} ;( supercronic does not support multiple variables..?

My current Crontab file without variables, worked OK


#TangoAPISync.get_deudas_cheques_de_los_clientes_r_e_s_t
0 */30 0-06 * * * * cd /var/www/html/app/ && ../vendors/bin/cake TangoAPISync.get_deudas_cheques_de_los_clientes_r_e_s_t  > /home/nobody/CRON_TangoAPISync.get_deudas_cheques_de_los_clientes_r_e_s_t.txt 2>&1

#PedidosYaApiSync.get_orderns_and_push_all_heart_beat_pedidos_ya_api_sync
0 * 00-05,12-23 * * * * cd /var/www/html/app/ && ../vendors/bin/cake PedidosYaApiSync.get_orderns_and_push_all_heart_beat_pedidos_ya_api_sync > /home/nobody/CRON_PedidosYaApiSync.get_orderns_and_push_all_heart_beat_pedidos_ya_api_sync.txt 2>&1

#MagentoApiSync.get_pedidos_comandas_magento_r_e_s_t
0 * 00-05,12-23 * * * * cd /var/www/html/app/ && ../vendors/bin/cake MagentoApiSync.get_pedidos_comandas_magento_r_e_s_t > /home/nobody/CRON_MagentoApiSync.get_pedidos_comandas_magento_r_e_s_t.txt 2>&1

#RappiApiSync.get_orderns_rappi_api_sync
0 * 00-05,12-23 * * * * cd /var/www/html/app/ && ../vendors/bin/cake RappiApiSync.get_orderns_rappi_api_sync > /home/nobody/CRON_RappiApiSync.get_orderns_rappi_api_sync.txt 2>&1
UserNotFound commented 1 year ago

Hi @EOM supercronic does support variables in the crontab, as documented in the Readme, and demonstrated below:

image

Your issue is that you're trying to access the variable within an inline shell script, and is an behavior you'll see even outside of supercronic does not work:

# FOO=bar; echo "$FOO"
bar
# FOO=bar; bash -c 'echo "$FOO"'

You verified this in your second post: you removed /bin/bash -c "" part of your command, which is why it works. You should be able to use the crontab from your first post if you remove /bin/bash -c "" there, as well.

EOM commented 1 year ago

Hi @UserNotFound, OK, with what you say, but the problem with the first crontab was that only the last task was executed, instead of all three. But if I generated a cron with only && in a line it doesn't fail, everything runs fine. That was the weird thing I noticed.

Example This does not fail either and runs OK and use without problem /bin/bash.


APP='CRON_APPS'
HOME='/home/nobody'
BIN_CAKE='vendors/bin/cake'
PATH_APP='/var/www/html/app'
CAKECMD='RappiApiSync.get_orderns_rappi_api_sync'

0 * 00-05,12-23 * * * * /bin/bash -c 'cd $PATH_APP && ../$BIN_CAKE $CAKECMD && ../$BIN_CAKE MagentoApiSync.get_pedidos_comandas_magento_r_e_s_t && ../$BIN_CAKE PedidosYaApiSync.get_orderns_and_push_all_heart_beat_pedidos_ya_api_sync' > ${HOME}/${APP}_all.txt 2>&1

Thank @UserNotFound for your answer as well