Question

cURL with cron job not working

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?

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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