Cron - gsutil not found
Asked Answered
T

2

7

gsutil has been installed here:

/usr/local/bin/gsutil

My crontab looks like this (i'm logged in as root):

 */1  *  *  *  * /home/deploy/cron/job.sh >> /home/deploy/cron/test.log 2>&1

job.sh:

#!/bin/sh
PATH="$PATH":/usr/local/bin/gsutil
now=$(date +"%m_%d_%y_%R");
cp /home/deploy/testfile.txt /tmp/testfile_$now.txt;
gsutil cp /home/deploy/testfile.txt gs://testbucket/testfile_$now.txt;

echo "saved file at $now";

When I look in my log file I see this:

/home/deploy/cron/job.sh: 5: /home/deploy/cron/job.sh: gsutil: not found
saved file at 07_20_15_13:03

Any idea what I'm doing wrong?

Tonnie answered 20/7, 2015 at 17:6 Comment(1)
$PATH does not contain full paths to binaries. It contains paths to the directories that contain the binaries. Either fix the PATH assignment or just use the full path to gsutil in the call itself.Fizzy
H
17

Had the same issue, you need to specify the full path when you call gsutil. In your case:

/usr/local/bin/gsutil/gsutil cp /home/deploy/testfile.txt gs://testbucket/testfile_$now.txt;
Heigho answered 5/10, 2015 at 15:24 Comment(2)
This solution helped me solve this problem, I'd like to add for anyone else that if your path is different for gsutil you can run "which gsutil" to get the correct path, using that path rather than /usr/local/bin/gsutil.Kochi
"whereis gsutil" will also workClique
M
3

yes, you have use the full path gsutil command to use in crontab

/root/gcloud/gsutil cp ...

Muraida answered 26/2, 2020 at 8:50 Comment(1)
You're right, I am just curious, any idea why this happens? Also, as pointed out by others, you can use which gsutil to find the path.Schade

© 2022 - 2024 — McMap. All rights reserved.