0

I have a script called urlretrieve.php that I have placed on my web server. Lets say the web address is www.example.com/urlretrieve.php and when you visit this website, a file from an ftp site is downloaded called download.zip and placed into the same folder as urlretrieve.php on the web server. I need this website to be visited (executed) once a week so that the ftp file downloads once a week. My question is, what should my cron job command be? At the moment I am using

0 14 * * 3 wget http://www.example.com/urlretrieve.php

and it isn't working. I have tested many others, but no luck.

I am using CPANEL.

Edit: This is the urlretrieve.php script

<?php 
$url = "ftp://alt.ncsbe.gov/data/ncvhis1.zip";
$fh = fopen(basename($url), "wb");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
curl_close($ch);
?>
  • Consider just using the command `php /your/path/to/urlretrieve.php` instead, and better still, move it to a non-web accessible location. – halfer Apr 16 '14 at 18:29
  • Doesn't work **HOW**? Did you bother looking at the wget docs to see how to tell it where to write the output file? As-is, it's going to be downloading that file into the home directory of whatever account this job is running under. – Marc B Apr 16 '14 at 18:29
  • If it is just a script somewhere, you can use web based cron services such as https://www.setcronjob.com/ – Jonathan Kuhn Apr 16 '14 at 18:30
  • The behaviour of the script it depends on the script itself you can post it. There's a particular reason for the script to be accessible directly in your web root? – TooShyToAsk Apr 16 '14 at 18:34
  • I have tried this command "php /home/user/public_html/path/to/file/downloads/urlretrieve.php" and nothing happens – user3529701 Apr 16 '14 at 18:36
  • you MUST provide more infos about the script. – TooShyToAsk Apr 16 '14 at 18:41
  • I have edited the OP with the script. – user3529701 Apr 16 '14 at 18:42
  • Is there a specific time the web server follows? I am wondering if the cron isnt executing becuase the web server and I are on different clocks? Also, still no luck. – user3529701 Apr 16 '14 at 19:22
  • "Still doesn't work" isn't much of a fault report, unfortunately. However, you are in luck! as there is a solution. It will require some debugging your end, though. Add in some simple `echo` statements at various points in your program. Then use `php /your/path/to/urlretrieve.php >> /your/log/file.log` to log the script's progress. You'll soon find out where it is getting stuck. (Of course, you'll want to reset your cron to fire more frequently whilst you are debugging). – halfer Apr 16 '14 at 20:45
  • Sorry I am new to crons. Do I need to create the log file or will the cron create it for me with the name I provide in the cron? Also, what echo statements should I insert? – user3529701 Apr 16 '14 at 20:56

1 Answers1

0

For this task you SHOULD use php CLI every friday at 8:10

10 8 * * 5 php /path/to/your/script.php
TooShyToAsk
  • 194
  • 2
  • I have tried this command "php /home/user/public_html/path/to/file/downloads/urlretrieve.php" and nothing happens – user3529701 Apr 16 '14 at 18:36
  • you still have "path/to/file" in your cron file's path. I'm assuming you actually want to use: /home/user/public_html/downloads/urlretrieve.ph‌​p – Danoweb Jan 27 '17 at 21:28