This question already has an answer here:
- Why crontab scripts are not working? 46 answers
I wrote a script to backup a database. When I execute it directly, it works. I tried to make it a cron job and while it runs (I checked with
service status cron) it seems that it silently fails.
Here is the script:
#!/bin/bash echo "Starting mongo backup" mkdir /home/ubuntu/backups docker exec -it mongodb mongodump --archive=/root/mongodump.gz --gzip docker cp mongodb:/root/mongodump.gz /home/ubuntu/backups/mongodump_$(date +%Y-%m-%d_%H-%M-%S).gz echo "Mongo dump complete" printf "[default]\naccess_key=\nsecret_key=\nsecurity_token=\n" > ~/.s3cfg s3cmd put /home/ubuntu/backups/* s3://my-backup-bucket/ echo "Copy to S3 complete" rm /home/ubuntu/backups/* -r echo "Files cleaned"
I used only absolute paths (EDIT: yeah actually I didn't), no environment variable, no un-escaped %. I don't know what I missed.