简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM