0

I am trying to trying to execute a script using corn job, the script runs as required when i run it manually at the terminal but fails when i run it through a cron job. How can i make it run via cron?

Error: 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

jarvis
  • 157
  • 1
  • 13
  • Looks like you figured out how to do it, however, this is now a built-in feature of GCE: https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop – Andy T Apr 22 '21 at 18:42

1 Answers1

0

I solved it using the following without making any changes to the cron job

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