Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用Shell脚本自动关闭GCE&;Gloud SDK_Linux_Shell_Google Cloud Platform_Google Compute Engine - Fatal编程技术网

Linux 使用Shell脚本自动关闭GCE&;Gloud SDK

Linux 使用Shell脚本自动关闭GCE&;Gloud SDK,linux,shell,google-cloud-platform,google-compute-engine,Linux,Shell,Google Cloud Platform,Google Compute Engine,我正在尝试使用corn作业执行脚本,当我在终端手动运行脚本时,脚本会按要求运行,但当我通过cron作业运行脚本时,脚本会失败。我如何使它通过cron运行 错误:gcloud:未找到命令 #!/bin/bash GCE_STATUS=$(gcloud compute instances list | awk '/my-gce-instance/' | awk '{print $NF}') REQ_STATUS="TERMINATED" if [[ $GCE_STATUS

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

错误:
gcloud:未找到命令

#!/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


我使用以下方法解决了这个问题,没有对cron作业做任何更改

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

看起来你已经知道怎么做了,但是,这是GCE的一个内置功能: