Crontab seems to start scripts but nothing happens

87 views Asked by At

I have defined quite a few cronjobs in my docker container, that I let running while I went for some holidays. When I came back, everything had stopped. It appears that the container restarted at some point during my time off and I didn't configure my docker well enough for it to restart the crontab service by itself.

However now that I have restarted it, my cronjobs do not work. I checked that the services are running, I can ensure that crontab is doing part of its job, because its entries are logged successfully in syslog. But my script doesn't get executed. I started it with a write into a logfile (my tasks are using Django commands and the python logging library), but the log file doesn't get updated.

Running the command manually from the command line is still working, my commands specify the absolute path for everything (even the python binary to use...). I don't know where to look at to understand what's wrong at this point.

Note : I did update some of my code since I came back from my holidays, but none should affect the starting log message that lies in my scripts.

As a test, I created a script bash containing a single line : echo "foo" > /path/to/some_non_exiting_file.txt. I edited cron using crontab -e and adding the line * * * * * myscript.sh. It turns out that the next minute, my file got created, but it was empty.

1

There are 1 answers

3
Dudi Boy On

Add this line to the top of your script after bash bang:

#!/bin/bash
source ~/.bash_profile

This line will include your bash login script with the relevant environment settings.