7

I have a list of cron jobs.

00 21 * * * sh ~/db_backup.sh

20 21 * * * sh ~/update.sh

* 5 1 * *  sh ~/db_vacuum.sh

The first job makes a backup of a database I have running on an Ubuntu server, this works as I verify the date the backup file was last modified using:

date -r db.sql

My third cron job just vacuums my db at the start of every month. My issue is in my second job. This job executes several url callbacks on a DJango application I am running:

sudo docker exec -it web_1 wget -t 0 "http://127.0.0.1:8080/admin/command1"
sudo docker exec -it web_1 wget -t 0 "http://127.0.0.1:8080/admin/command2"
sudo docker exec -it web_1 wget -t 0 "http://127.0.0.1:8080/admin/command3"
sudo docker exec -it web_1 wget -t 0 "http://127.0.0.1:8080/admin/command4"

I check the expected outputs and it seems the file was not executed at all, the strange thing is if I execute it manually with the command:

sh ~/update.sh

It runs flawlessly, is there some catch with wgets I am missing? In case it is not obvious, the wget commands are pointing towards a docker container running the server.

UPDATE:

I tried attaching log files as output files to the wget commands in my .sh file. After checking back after the established cron job execution time, there were no log files in the directory.

I then checked the actualy system logs and I noticed this message appeared in the log the second after my .sh file was executed.

(CRON) info (No MTA installed, discarding output)

Could this be related somehow?

10
  • I guess docker doesn't require the sudo password, right?
    – kos
    Dec 15, 2015 at 10:35
  • The sudo was something I added when I noticed it was not working to see if that made a difference, it does not seem to be related.
    – GreenGodot
    Dec 15, 2015 at 10:38
  • Use full path to docker: /usr/bin/docker
    – heemayl
    Dec 15, 2015 at 10:42
  • 1
    If your user is not in the docker group (grep '^docker' /etc/passwd) docker requires the sudo password; if docker requires the sudo password and you didn't add docker to NOPASSWD in /etc/sudoers, the sudo command is halting the execution of the script.
    – kos
    Dec 15, 2015 at 10:42
  • 1
    Perhaps you overlook the point that cron jobs by default are run with /bin/sh using PATH=/usr/bin:/bin. I believe docker is installed elsewhere. Dec 23, 2015 at 12:25

2 Answers 2

3
+25

Your problem is using sudo in your script. Cron can never enter your sudo password.

2

I notice you use sh to invoke the cronjob however sh is a subset of bash and might not be able to execute your cronjob. Also running the task manually is not necessarily the same as running it by cron. Please change sh to bash in the cronjob and see what happens.

The errormessage about MTA that you see in the logfile means you have no Mail Transfer Agent installed, meaning you don't have software installed to send mail messages. Cron tries to send mail messages to inform you about something. It might be an errormessage about the failing cronjob.

2
  • I changed the command to '30 21 * * * bash ~/update.sh' but still no luck. With regards to the MTA messages, can the message in the file be routed to a file instead of an email?
    – GreenGodot
    Dec 21, 2015 at 10:09
  • You can route the message to a file by changing the cronjob to this: 20 21 * * * sh ~/update.sh >> /path /to your/file.log 2>&1 change the path and filename according to your likings and the command should be on one line of course. Make sure cron has access rights to that particular file but ususally it should have those rights automatically.
    – wie5Ooma
    Dec 21, 2015 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .