Search code examples
crongcloudbucketgsutil

Why gsutil cp command does not work in a cron job configured in a compute engine instance?


I have the follow command: gsutil -m cp file-to-copy gs://target-bucket

When I run from the command line it works fine. But, when I schedule a cron job, the file copy does not occur, although the cron job is executed.

Could anybody help me?


Solution

  • It's likely that your cron job is either running the command as a different user than the one you have credentials set up for, or the cron job doesn't have access to your credentials. If you run gsutil version -l, you should see the credential files being loaded on the config path(s): line. Make sure you see the same config file being loaded when running your cron job.

    If you want to see the output of your cron job, try routing stdout and stderr to a file, e.g.

    /path/to/google-cloud-sdk/bin/gsutil ... 1>/tmp/gsutil_output.txt 2>&1