我如何在由Google云存储finalize事件触发的python脚本中运行bash脚本?

问题描述 投票:0回答:1

当将新文件添加到Google云存储分区时,我想运行bash脚本。现在,将文件添加到gcs时,我可以运行python脚本。我尝试从python脚本中调用bash脚本,但在shell或日志中看不到任何输出。

这是我的函数main.py,已订阅gcs finalize事件

import subprocess
# [START functions_helloworld_storage_generic]                                                                                                                                                                                          
def hello_gcs_generic(data, context):
    subprocess.call("alert.sh", shell=True)
    """Background Cloud Function to be triggered by Cloud Storage.                                                                                                                                                                      
       This generic function logs relevant data when a file is changed.                                                                                                                                                                 

    Args:                                                                                                                                                                                                                               
        data (dict): The Cloud Functions event payload.                                                                                                                                                                                 
        context (google.cloud.functions.Context): Metadata of triggering event.                                                                                                                                                         
    Returns:                                                                                                                                                                                                                            
        None; the output is written to Stackdriver Logging                                                                                                                                                                              
    """
    print('Event ID: {}'.format(context.event_id))
    print('Event type: {}'.format(context.event_type))

这里是alert.sh bash脚本

echo "FILE ADDED"
python bash google-cloud-platform publish-subscribe
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.