2

I want to hit a URL of my application through cron job. I have done the following things:

1) Opened the terminal

2) Did crontab -e which gives me an editor that allows me to put statements

3) Pasted the URL that needs to be hit after specified interval of time:

curl -s  http://www.example.com/controller/function_to_execute

This cron job will run every minute

4) Saved the cron and again on terminal did crontab -l, and I could see my cron

This scheduler isn't working, don't know why. I tried curl on the terminal directly expecting some output, but after 5 minutes it gives me the result

curl: (7) couldn't connect to host

If I hit my URL on browser directly then my job gets successfully executed!

Have I made some mistake while making entry in the cron?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Aditya Achar
  • 173
  • 1
  • 1
  • 12
  • have you tried this? `* * * * * curl -s http://www.example.com/controller/function_to_execute` – Muhammad Bilal Nov 09 '15 at 07:55
  • Yes I have tried with * * * * that is the proper way to execute the cron for every minute. Is it some permission related issue that I am getting curl: (7) couldn't connect to host when I CURL on terminal directly? – Aditya Achar Nov 09 '15 at 07:59
  • Possible duplicate of [How to resolve cURL Error (7): couldn't connect to host?](http://stackoverflow.com/questions/9922562/how-to-resolve-curl-error-7-couldnt-connect-to-host) – Muhammad Bilal Nov 09 '15 at 08:01
  • Referring to one of the solutions to disable (SELINUX=enforcing to SELINUX=disabled) I have checked that file and SELINUX is already showing as disabled. – Aditya Achar Nov 09 '15 at 08:17
  • It sounds like you have two separate issues here, `cron` and `curl`. Try putting something in `cron` like `* * * * * touch /tmp/cron_ok`. – Tom Zych Nov 09 '15 at 08:34

2 Answers2

1

First you need to create the php script and run the script using cronjob
1)Open terminal and type crontab -e
2)Edit the file and write the following code to run the php script in background

*/1 * * * * php /yourpath/yourphpfile.php

3) Create yourphpfile.php and write the code to hit the url
you have to execute and test the yourphpfile.php before doing cronjob

Abdul Razak
  • 2,654
  • 2
  • 18
  • 24
1

Whoops!..tried to just curl www.google.com and gave the following output in form of HTML tags "302 Document has moved", Also I am not able to ping the application itself from the terminal but it is accessible publicly

So cron job getting executed is out of question :P

Aditya Achar
  • 173
  • 1
  • 1
  • 12