为什么GCE上的命令在控制台终端上工作,但不能作为Cron作业

问题描述:

我可以使用Web控制台在我的实例上运行此命令;为什么GCE上的命令在控制台终端上工作,但不能作为Cron作业

的rsync的gsutil -d -r /我的路径GS://我斗

但是当我尝试我的SSH远程终端上我得到这个错误;

[email protected]: gsutil rsync -d -r /my-path gs://my-bucket 
Building synchronization state... 
INFO 0923 12:48:48.572446 multistore_file.py] Error decoding credential, skipping 
    Traceback (most recent call last): 
     File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/multistore_file.py", line 381, in _refresh_data_cache 
     (key, credential) = self._decode_credential_from_json(cred_entry) 
     File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/multistore_file.py", line 400, in _decode_credential_from_json 
     credential = Credentials.new_from_json(json.dumps(cred_entry['credential'])) 
     File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/client.py", line 292, in new_from_json 
     return from_json(s) 
     File "/usr/lib/google-cloud-sdk/platform/gsutil/third_party/apitools/apitools/base/py/credentials_lib.py", line 356, in from_json 
     data['token_expiry'], oauth2client.client.EXPIRY_FORMAT) 
    TypeError: must be string, not None 
    Caught non-retryable exception while listing gs://my-bucket/: Could not reach metadata service: Not Found 
    At source listing 10000... 
    At source listing 20000... 
    At source listing 30000... 
    At source listing 40000... 
    CommandException: Caught non-retryable exception - aborting rsync 
+0

您需要确保分配给该实例的服务帐户具有允许其写入存储桶的IAM权限。 – danemacmillan

我通过将用户切换到创建项目时创建的默认CGE来解决此问题。虚拟机上的根目录没有权限运行gsutil命令。