Report this

What is the reason for this report?

cURL with cron job not working

Posted on April 24, 2018

Hello

I’ve tried to create a cron job with a curl to a specific page on my website. On that page, when loaded, it’s sending out an e-mail to some specific people. I’ve tested the script, and it’s working just as intended.

What I’ve done to enable my cron job is:

  • Log in to my server
  • Run: sudo crontab -e
  • Added: * 17 * * * curl http://url.com/cron/email to the file and saved

What I tried to here was to make a cron job calling the url once a day at 5pm. For some reason this is never happening - not even at another time of the day, it’s like it’s never run.

What am I doing wrong?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @aha:

One more tip for debugging: to see the logged results of the cron task you set up to run every minute, use grep CRON /var/log/syslog to print out all the lines related to cron. You should see something like:

CRON[2179]: (root) CMD (/usr/bin/curl http://url.com/cron/email)

However - you are right, there is a big difference between running curl http://url.com/cron/email and visiting http://url.com/cron/email in the browser:

When you visit http://url.com/cron/email in the browser, if it returns an HTML doctype, the browser will: A) Download the HTML, B) Download any Javascript, CSS, Images referenced in the HTML, C)Render the page, D)Execute all Javascript.

When you curl http://url.com/cron/email, it is just A) Downloading the HTML

So if the thing that causes the email send is executed via javascript on the page, curling it will not help.

View the original comment

If you’re looking for a simpler cron job solution, you might consider webcron services like easycron.com which will load a specific URL at a given time.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.