问题描述
我有一个.sh文件存储在GCS中.我正在尝试通过Google Cloud Shell安排.sh文件.
I have a .sh file that is stored in GCS. I am trying to schedule the .sh file through google cloud shell.
我可以使用gsutil cat gs://miptestauto/baby.sh | sh
命令运行同一文件,但无法计划它.
I can run the same file using gsutil cat gs://miptestauto/baby.sh | sh
command but not able to schedule it.
以下是我安排文件的代码:
Following is my code for scheduling the file:
16 17 * * * gsutil cat gs://miptestauto/baby.sh | sh
它显示消息为自动保存..完成",但是当我使用crontab -l
It displays the message as "auto saving..done" but the scheduled job is not get displayed when I use crontab -l
# contents of .sh file
bin/bash
bq load --source_format=CSV babynames.baby_destination13 gs://testauto/yob2010.txt name:string,gender:string,count:integer
请任何人告诉我如何使用Google Cloud Shell进行计划.我没有使用计算引擎/应用引擎.只是想使用云外壳计划它.
Please can anyone tell me how schedule it using google cloud shell.I am not using compute engine/app engine. Just wanted to schedule it using the cloud shell.
预先感谢您:)
推荐答案
要计划脚本,首先要创建一个项目(如果没有).我假设您已经有一个项目,因此,如果是这种情况,只需创建要调度此脚本的实例即可.
To schedule a script you first have to create a project if you don’t have one. I assume you already have a project so if that’s the case just create the instance that you want for scheduling this script.
要创建新实例:
-
在Google Cloud Platform Console上,点击Products&服务,该图标是位于左上角的四个栏的图标.
At the Google Cloud Platform Console click on Products & Services which is the icon with the four bars at the top left hand corner.
在菜单上转到计算"部分,将鼠标悬停在Compute Engine上,然后单击"VM实例".
On the menu go to the Compute section and hover on Compute Engine and then click on VM Instances.
在身份和API访问"部分中,提供对Storage API的访问范围,以便在需要时可以对存储桶进行读写;默认访问范围仅允许您阅读.还要启用BigQuery API.
In the Identity and API access section, give access scope to the Storage API so that you can read and write to your bucket in case you need to do so; the default access scope only allows you to read. Also enable BigQuery API.
创建实例并访问存储桶后,只需在新实例内创建cron作业:在将要执行cron作业的用户帐户中,运行crontab -e并编辑该文件以运行将执行baby.sh脚本的cron作业.以下文档链接应该可以帮助您.
Once you have the instance created and access to the bucket, just create your cron job inside your new instance: In the user account under which the cron job will execute, run crontab -e and edit this file to run the cron job that will execute your baby.sh script.The following documentation link should help you with this.
请注意,如果要查看脚本的输出,则可能需要到您当前的终端.
Please note, if you want to view output from your script you may need to redirect it to your current terminal.
这篇关于如何使用Google Cloud Shell安排Shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!