0

I am trying to execute this script that will go fetch data from a site and import it into my database.

I have created the cronjob and waited for 20 minutes. There is no error or result, it is just silent like nothing happened.

I am also not getting an email showing the result of the command. How can I execute this script and also receive the result via email?

This is the cronjob I am currently using:

20  *   *   *   *   /usr/bin/GET http://example.com/wp-content/plugins/ScriptName/scrap_data2.php?request_type=import_animes&site=2
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • Is the url you have in the cronjob what is supposed to execute the script? Or are you supposed to get data from that url and then do something with it? – Joe P. Jan 22 '18 at 17:46
  • @JoeP. Thanks for the reply. Yes, that is the url executing the script. – Moz Tycoon Jan 22 '18 at 17:56
  • Possible duplicate of [How to create cron job using PHP?](https://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php) – William Perron Jan 22 '18 at 21:08
  • Are you not able to run the script directly from that server? Or are you supposed to get data from that url and then do something with it? – Joe P. Jan 23 '18 at 16:06

1 Answers1

0

Although Hostgator does use GET as one of its cron examples; the usual way to "run" a script from cron via its http link is to use "wget" or "curl".

I beleive "GET" is part of "libwww-perl" package and it may depend on where or whether this is installed. Try using WGET instead.

20 * * * * wget -O /dev/null http://example.com/wp-content/plugins/ScriptName/scrap_data2

'-O /dev/null' above is used to ditch cron wgets output as you won't need it since your script emails success.

scytale
  • 1,339
  • 1
  • 11
  • 14
  • I tried that but unfortunately it did not work. The script did not executed or send an email of command results. – Moz Tycoon Jan 22 '18 at 19:13
  • just checked a working one of mine `40 1 * * * nice -n15 wget -O /dev/null --user-agent="Mozilla/5.0 (Windows NT 5.2; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" "http://example.com/somedir/some-script.php"` the "script link" is in quotes and I've added a user agent (some servers may require them?). nice -n15 is probably irrelevant it just makes script run at low resource priority. Other than try CURL nothing else to suggest if this example does not help. – scytale Jan 22 '18 at 19:42
  • I did this `/usr/bin/wget -O -q 'https://your_site_url.com/wp-content/plugins/scriptname/scrap_data.php?request_type=import_animes&site=1'` and it worked. – Moz Tycoon Jan 29 '18 at 00:57