I am new to SSH & cronjobs so probably I am doing something wrong.
I am using a Google Cloud Engine for hosting my SSH Linux instance and I want to delete a snapshot by its name with a cronjob (I have also a create snapshot cronjob that works fine).
So I wrote this script:
1 * * * * sudo gcloud compute snapshots delete my-snapshot-name -q
This script should delete the snapshot every 1 minute (the 1 minute is just in order to see the result immediately after I will see it works, I will change it accordingly).
The snapshot is not deleted.
If I run the same script, not in the cronjob then it deletes it:
sudo gcloud compute snapshots delete my-snapshot-name -q
Some more details about how I create the cronjob:
- In the google cloud SSH I run crontab -e.
- I write the cron script written above.
- Click on Ctrl + X.
- It asks if I want to save modified buffer – I click Y.
- It offers to write the file name to
/tmp/crontab.xxxxxx/crontab
, I click enter and the cronjob is created.
What am I doing wrong? What could be the cause that the delete does not work?
Advertisement
Answer
It’s better to add this to root crontab than using sudo.
Not so familiar with GCE, however a few things to try,
1) Use the complete path to the gcloud binary
2) Check /var/log/syslog for ‘CRON’ and check what the error is.