如何使用 Google Cloud Shell 安排 shell 脚本? [英] how to schedule the shell script using Google Cloud Shell?

查看:32
本文介绍了如何使用 Google Cloud Shell 安排 shell 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储在 GCS 中的 .sh 文件.我正在尝试通过 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

请谁能告诉我如何使用谷歌云外壳安排它.我没有使用计算引擎/应用程序引擎.只是想使用 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.

创建新实例:

  1. 在 Google Cloud Platform Console 中,点击 Products &服务,即左上角带有四个横条的图标.

  1. At the Google Cloud Platform Console click on Products & Services which is the icon with the four bars at the top left hand corner.

在菜单上,转到计算"部分,将鼠标悬停在计算引擎"上,然后单击虚拟机实例".

On the menu go to the Compute section and hover on Compute Engine and then click on VM Instances.

在身份和 API 访问部分,为存储 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 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆