Cron job to download file

Associate
Joined
31 Oct 2012
Posts
241
Location
Glasgow, Scotland
Hey,

I'm trying to download a file then open a php file to process it. I've written the php script and of course it works if I upload the file manually and open the php file, but it's something that I need to be done everyday. I've searched for what I should put in as a cron job but no commands (if that's the correct term) have worked so far.

Not sure if it matters, but the download path contains variables as it's generated on the fly for the data that I need (the variables I use are the same every day though so I don't need the url to change) my point is it takes a little while for the download to initiate, I don't think that matters but including it anyway in-case it does.

Wondering if anyone has done something like this before and knows how to go about it.

Regards,
Frxn
 
Associate
Joined
16 Jan 2008
Posts
2,350
Depending on if your host supports it you could use the php "exec" command.

PHP:
$cmd_download = "wget http://domain.com/thefile.filetype -q -o /dev/null"; 
$cmd_process = "wget http://domain.com/thephpscript.php?var1=thefile -q -o /dev/null"

exec($cmd_download ." && ". $cmd_process);

You could change the "/dev/null" part to keep a log if you so wish. Also, there might be a better way, but this is the best I could come up with for the moment.

Hope that helps.
 
Soldato
Joined
3 Jun 2005
Posts
3,119
Location
The South
Entirely depends on the processing your doing on the file and file sizes. But you could use file_get_contents() function or fopen or alternatively cron WGET and cron (you run two cron jobs) the 'processing' script but just get it to 'process' the data if the file exists.
 
Associate
OP
Joined
31 Oct 2012
Posts
241
Location
Glasgow, Scotland
Thanks for the input guys!
Unfortunately the code cheechm supplied I couldn't get to work.

I found this though:
PHP:
/usr/bin/wget -O "/path/to/save/file" "http://download/url/";
Saved it as an .sh file, then put the path to the .sh in as a cron job and it's working :) then set it to run at 1am everyday and a second job to run the .php file 5 min later.

What do the -q -o things mean?
 
Associate
OP
Joined
31 Oct 2012
Posts
241
Location
Glasgow, Scotland
"-q" means no output.

"-o" means output any info to a particular file (in the case above it is "no where" - /dev/null)

Ah, thanks for that, still new to this side of things so it goes over my head. I take it the output is the same as what is sent by email (if set in cpanel for example)?
 
Back
Top Bottom