-1

I am using https://stackoverflow.com/a/42955871/308851 and it works from command line but not from cron. I even tried running the script with env -i but it stubbornly works.

#!/bin/bash
filename=$(date '+%Y-%m-%d').gz
docker exec -t elastic_db.1.$(docker service ps -f 'name=elastic_db.1' elastic_db -q --no-trunc | head -n1) mysqldump example |gzip -9 > /container/$filename
docker exec -t elastic_drupal.1.$(docker service ps -f 'name=elastic_drupal.1' elastic_drupal -q --no-trunc |head -n1) rclone --config /etc/rclone.conf move /app/$filename example:example/dump/

This compresses a 0 byte file when ran from cron but works just fine otherwise. What am I doing wrong?

chx
  • 11,270
  • 7
  • 55
  • 129
  • 1
    cron jobs run with a really minimal environment, including a `PATH` that probably doesn't include the directory that `docker` is in. I don't think `env -i` fully emulates this. Try setting `PATH` explicitly, either in your crontab or in the script. Also, whenever something is going wrong in a cron job, try capturing error output with something like `2>/tmp/cron-job.log`. – Gordon Davisson Sep 02 '20 at 05:06

1 Answers1

0

Gordon Davisson's comment is correct: changing docker to /usr/bin/docker worked.

chx
  • 11,270
  • 7
  • 55
  • 129