【问题标题】:Automating GCE Shut down using Shell Script & Gloud SDK [duplicate]使用 Shell Script 和 Gloud SDK 自动关闭 GCE [重复]
【发布时间】:2021-04-22 14:17:50
【问题描述】:

我正在尝试使用玉米作业执行脚本,当我在终端手动运行脚本时,该脚本按要求运行,但当我通过 cron 作业运行它时失败。如何让它通过 cron 运行?

错误:gcloud: command not found

#!/bin/bash

GCE_STATUS=$(gcloud compute instances list | awk '/my-gce-instance/' | awk '{print $NF}')
REQ_STATUS="TERMINATED"


if [[ $GCE_STATUS != $REQ_STATUS ]]; 
then
    echo "Google Compute Engine is currently Running - Shutting Down the Instance"
    gcloud compute instances stop my-gce-instance --zone=us-central1-a
else
    echo "Google Compute Engine is Already TERMINATED!!"
fi

【问题讨论】:

标签: linux shell google-cloud-platform google-compute-engine


【解决方案1】:

我使用以下方法解决了它,而没有对 cron 作业进行任何更改

GCLOUD="/Users/user-name/google-cloud-sdk/bin"
GCE_STATUS=$(${GCLOUD}/gcloud compute instances list | awk '/nc-de-docker-v3/' | awk '{print $NF}')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 2016-08-06
    • 2011-12-17
    • 1970-01-01
    相关资源
    最近更新 更多