Search code examples
bashdockerubuntucron

Execute a "docker exec -it" command within in a ubuntu cron job


For a daily database backup, I created the following cron job :

File : crontab -e

SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin


* * * * * /bin/bash /var/path/deploy/database/scripts/backup.sh

File : /var/path/deploy/database/scripts/backup.sh

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

cp -r /var/path/deploy/database/scripts /var/bricoolpathpostgresql/data

chmod 755 -R /var/path/postgresql/data

docker exec -it database /var/lib/postgresql/data/scripts/pg_backup_rotated.sh

When I execute the script directly it works well and the backup is created successfully. But the script is being excuted from the cron job the command docker exec -it database /var/lib/postgresql/data/scripts/pg_backup_rotated.sh does not seem to work.

I have no error output in /var/log/syslog


Solution

  • as Danny Ebbers mentioned in comment, the problem ws the -i argument in Docker command.