Ayra
Ayra

Reputation: 348

Curl command in cron not working properly

I'm using curl in a cronjob :

*/3 * * * * curl -XPUT "elasticsearch3:9200/_snapshot/edump/snapshot-$(date +%Y_%m_%d)?pretty" -H 'Content-Type:application/json'-d'{"ignore_unavailable":true,"include_global_state":false}' > /home/log

Which perfectly worked manually. However, in my cronjob (that also have simpler cronjob to make sure the problem isn't just that my cron isn't working (ex : */1 * * * * curl http://google.fr > /home/google_logwhich is also working) it doesn't work.

I don't even have the '/home/log' to help me and I really don't know what to do ?

Upvotes: 1

Views: 10133

Answers (3)

sbha
sbha

Reputation: 10432

It's possible curl used by cron might be different from what's used in the terminal/shell. Check which curl in the terminal (where it's working), and then in either cron or the shell script rather than just curl https://www.example.com/ use that full path: /home/myusername/anaconda3/bin/curl https://www.example.com/.

Upvotes: 0

Ayra
Ayra

Reputation: 348

I found :) 1 : put the command in a script and use cron to execute the script : Working 2 : cron interpret "%" in his way so you have to escape it. (http://www.ducea.com/2008/11/12/using-the-character-in-crontab-entries/)

Upvotes: 3

Val
Val

Reputation: 217554

I would put the curl command inside a script file

snapshot.sh:

#!/bin/sh
curl -XPUT "elasticsearch3:9200/_snapshot/edump/snapshot-$(date +%Y_%m_%d)?pretty" -H 'Content-Type:application/json'-d'{"ignore_unavailable":true,"include_global_state":false}'

Make sure to make that file executable (chmod u+x snapshot.sh) and then simply modify your cronjob like this:

*/3 * * * * /path/to/snapshot.sh > /home/log

Upvotes: 4

Related Questions