Reputation: 8162
I'm trying to upload files to Google Cloud Storage using cron in Linux, but it fails. I have also set path and configuration in my script file as :
PATH=/bin/gsutil/
export BOTO_CONFIG="/home/ashu/.boto"
# rest of script
But still nothing works.
Upvotes: 2
Views: 4104
Reputation: 21
I had the same issue on Ubuntu 20.04 and I found that the simplest solution was to create a softlink between my gsutil installation and the system bin folder like this:
sudo ln -s /snap/bin/gsutil /usr/bin/gsutil
Upvotes: 2
Reputation: 31
you can try using the full path gsutil command to use in crontab
/root/gcloud/gsutil cp ...
Upvotes: 0
Reputation: 31
And if you are using default installation provided by Google Cloud - Compute Engine, most probably gsutil is in /snap/bin
PATH=$PATH:/snap/bin
Upvotes: 3
Reputation: 8162
I removed my pip install and used following link for installation : https://cloud.google.com/storage/docs/gsutil_install#specifications.
Also use of sudo should be avoided for path and export as it can lead to some issues.
PATH=$PATH:/root/gsutil/
export BOTO_CONFIG="/root/.boto"
# rest of script
Above code works well.
Upvotes: 1
Reputation: 11
Apart from modifying the PATH, as suggested by pjz, did you try to look at the actual output from gsutil / cron?
Which reason is given for the commend failing? In case you need to catch the output of gsutil, you can redirect standard output and error (stdout and stderr) to a file, and save it there.
E.g. if you're using Bash, you could redirect the output to gsutil_log.txt
by modifying your crontab as:
*/1 * * * * /mypath/myscript.sh >> $HOME/gsutil_log.txt
This will redirect stdout
and stderr
and append any output to gsutil_log.txt
in $HOME
for myscript.sh
that is called every minute by cron.
If the output is helpful, that should advance you a bit with debugging.
Upvotes: 1
Reputation: 43057
It's a bit safer to do
PATH="$PATH":/bin/gsutil/
so you don't kill access to the usual places like /bin
and /usr/bin
and etc. You may not use them directly, but scripts you call might!
update: @ComputerDruid rightly points out that quotes keep spaces from causing trouble.
Upvotes: 2