I have a groovy script that fetches data about all of my app sales with various companies and generates reports for me. This has been working well, but I've migrated to a new server and now I'm running into a problem.
To download Android app sales from Google Play, you have to use the gsutil
command to copy the sales data from Google Storage. So, in my groovy script I execute that command. It works just fine on my old server and when I issue the same command in my shell on the new server it works.
It just doesn't work on the new server from within the groovy script. Here is the error I get:
$ ./fetch_googleplay_report.groovy 2017-01-29
Fetching 2017-01-29 for Android Google Play
Running command: /usr/bin/gsutil cp -r gs://pubsite_prod_rev_XXXXXXXXXXXXX/sales/salesreport_201701.zip .
gsutil command output:
gsutil command error output: which: no python2 in ((null))
which: no python2.7 in ((null))
Traceback (most recent call last):
File "/usr/lib64/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 75, in <module>
main()
File "/usr/lib64/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 59, in main
'platform/gsutil', 'gsutil', *args)
File "/usr/lib64/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 45, in ExecutePythonTool
execution_utils.ArgsForPythonTool(_FullPath(tool_dir, exec_name), *args))
File "/usr/lib64/google-cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 170, in ArgsForPythonTool
python_executable = kwargs.get('python') or GetPythonExecutable()
File "/usr/lib64/google-cloud-sdk/lib/googlecloudsdk/core/execution_utils.py", line 59, in GetPythonExecutable
raise ValueError('Could not find Python executable.')
ValueError: Could not find Python executable.
$ which python
/usr/bin/python
$ which python2
/usr/bin/python2
Python is definitely installed and in my path, but when gsutil is running when called by my groovy script, it can't seem to find it. I'm guessing from the stacktrace that when it says no python2 in ((null))
it means that it's path is null. I'm not sure though.
Here is the groovy code snippet that is executing the command:
def cmd = "/usr/bin/gsutil cp -r gs://pubsite_prod_rev_XXXXXXXXXXX/sales/$reportfilename .";
println("Running command: $cmd")
def out = new StringBuffer(), err = new StringBuffer()
def proc = cmd.execute([], incomingdir)
proc.consumeProcessOutput(out, err)
proc.waitForOrKill(5000)
println("gsutil command output: $out")
println("gsutil command error output: $err")
EDIT: If I move the gsutil command into a shell script wherein I specifically source my .bash_profile to set up my PATH and have the groovy script call that shell script instead, then the file gets downloaded just fine.
So, this does appear to be a problem with gsutil getting called from a groovy script. Any ideas?