Google cloud SDK code to execute via cron -
i trying implement automated code shut down , start vm instances in google cloud account via crontab. os ubuntu 12 lts , installed google service account can handle read/write on google cloud account.
my actual code in file /home/ubu12lts/cronfiles/resetvm.sh
#!/bin/bash echo y | gcloud compute instances stop my-vm-name --zone us-central1-a sleep 120s gcloud compute instances start my-vm-name --zone us-central1-a echo "completed"
when call above file this,
$ bash /home/ubu12lts/cronfiles/resetvm.sh
it works perfect , job.
now wanted set in cron automatically every hour. did
$ sudo crontab -e
and added code in cron
0 * * * * /bin/sh /home/ubu12lts/cronfiles/resetvm.sh >>/home/ubu12lts/cron.log
and made script executable
chmod +x /home/ubu12lts/cronfiles/resetvm.sh
i tested crontab adding sample command of creating .txt file sample message , worked perfect.
but above code gcloud sdk doesn't work through cron. vm doesn't stop neither starts in gc compute engine.
anyone can please?
thank much.
you have added entry root's crontab, while cloud sdk installation setup different user (i guessing ubu121lts).
you should add entry in ubu121lts's crontab using:
crontab -u ubu121lts -e
additionally entry scheduled run on 0th minute every hour. intended?
Comments
Post a Comment