docker exec is not working in cron

user555 picture user555 · May 7, 2016 · Viewed 18.3k times · Source

I have pretty simple command which is working fine standalone as a command or bash script but not when I put it in crontab

40 05 * * * bash /root/scripts/direct.sh >> /root/cron.log

which has following line

PATH=$PATH:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/root/
# Mongo Backup
docker exec -it mongodb mongodump -d meteor -o /dump/

I tried to change the url of script to /usr/bin/scirpts/ no luck

I even tried to run script directly in cron

26 08 * * * docker exec -it mongodb mongodump -d meteor -o /dump/ >> /root/cron.log

with no luck, any help appreciated.

EDIT

I don't see any errors in /root/cron.log file either

Answer

VDR picture VDR · May 24, 2016

Your docker exec command says it needs "pseudo terminal and runs in interactive mode" (-it flags) while cron doesn't attach to any TTYs.

Try changing your docker exec command to this and see if that works?

docker exec mongodb mongodump -d meteor -o /dump/