I
I
Igor2015-07-26 16:43:01
Python
Igor, 2015-07-26 16:43:01

How to set up cron, gsutil and subrocess?

Can't run command via cron

gsutil cp /home/ubuntu/data.json gs://project/data.json
which in turn is run through subprocess.
$ crontab -e
*/1 * * * * /usr/bin/python /home/ubuntu/ex.py > home/ubuntu/cronlog.txt 2>&1 >/dev/null 2>&1

I read in Google that cron does not see environment variables, so I wrote the following piece of code for the test:
from subprocess import call

PATH="/home/ubuntu/lib/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
BOTO_CONFIG="/home/ubuntu/.config/gcloud/legacy_credentials/email/.boto"

call('gsutil cp /home/ubuntu/data.json gs://project/data.json', shell=True)

But at the same time, subrocess does not execute the gsutil command via cron, nothing is written to the log.
If you run the script with handles, then everything works fine.
What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anelyubin, 2015-07-26
@IgorPosmashny

Try writing the full path to the gsuitil command. Well, that is, cron does not know where this utility is located and cannot execute it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question