1

I have this cron:

00 0 * * * root /home/bitnami/backup.sh > /home/bitnami/backup.log

The Backup script contains:

#!/bin/bash

cd /tmp
file=$(date +%Y-%m-%d).sql
mysqldump \
  --host localhost \
  --port 3306 \
  -u user \
  --password="123" \
  bitnami > ${file}
if [ "${?}" -eq 0 ]; then
  gzip ${file}
  aws --region us-west-2 s3 cp ${file}.gz s3://backups/fc-wiki/
  rm ${file}.gz
else
  echo "Error backing up mysql"
  exit 255
fi

Which works fine when executing it by hand (sudo .\backup.sh)

When the crontab runs it only logs the following error in backup.log: Error backing up mysql

Is there a problem how I'm setting up the cron tab with the piping to log perhaps? Even without the piping it doesn't work.

Roger Far
  • 341
  • 5
  • 17
  • Check your syslog for any errors. – Michael Hampton Dec 13 '18 at 01:01
  • ***cron runs your command in a restricted environment.** What environment variables are available is likely to be very limited. Typically, you'll only get a few variables defined, such as `$LOGNAME` `$HOME,` and `$PATH`. Of particular note is the PATH is restricted to `/bin:/usr/bin`. The vast majority of "my cron script doesn't work" problems are caused by this restrictive path"* – HBruijn Dec 13 '18 at 12:30

0 Answers0