Skip to content
Advertisement

ssh cronjob delete not working

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:

  1. In the google cloud SSH I run crontab -e.
  2. I write the cron script written above.
  3. Click on Ctrl + X.
  4. It asks if I want to save modified buffer – I click Y.
  5. 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.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement