1

I am very new using cron jobs, and I was wondering if there was a way to save this XML file 'http://xml.weather.yahoo.com/forecastrss?p=75039' and save it to a folder in my hosting, somewhere like '/urban/test-page/'I have no idea if this is even possible since the file is in another server, so I am unsure if I can do it this way, or if I should just use a VBscript to accomplish this task.

Thanks for any information that might help me with this.

Riquelmy Melara
  • 849
  • 2
  • 11
  • 28

1 Answers1

2

You can use wget with -P option for specifying the directory to save.

wget http://xml.weather.yahoo.com/forecastrss?p=75039 -P /urban/test-page/

and to specify the filename, add -O filename.extension. e.g.:

wget http://xml.weather.yahoo.com/forecastrss?p=75039 -P /urban/test-page/ -O forecast.xml

You will need to make sure that the job is run by a user with permissions for the folder you want to save to.

To set this up as a cronjob, running once a day at 1pm, run:

0 13 * * * wget http://xml.weather.yahoo.com/forecastrss?p=75039 -P /urban/test-page/
baao
  • 71,625
  • 17
  • 143
  • 203
  • I am going to test this and I will mark this as an answer if it works properly. – Riquelmy Melara Jan 29 '15 at 22:31
  • I'm looking forward to it. :) – baao Jan 29 '15 at 22:32
  • another question, do I have to specify the name of the file?, right now it failed and said it No such file or directory '/domains/html/urban/wp-content/themes/canvas-child/xml/forecastrss.xml/forecastrss?p=75039' – Riquelmy Melara Jan 29 '15 at 22:42
  • no, but the directory you want to save to has to exist – baao Jan 29 '15 at 22:44
  • Will it overwrite a file that is already there with the same name? or do I have to delete the file before downloading again? sorry for so many questions, and thanks a million for your help – Riquelmy Melara Jan 29 '15 at 22:46
  • No problem, and yes it will overwrite the file if it is the same filename – baao Jan 29 '15 at 22:47
  • I just changed the right path and it downloaded the file!, but it didn't specify the right name or the XML extension, is there a way to do that? – Riquelmy Melara Jan 29 '15 at 23:26
  • Sure there is, simply add -O filename.xml @RiquelmyMelara – baao Jan 29 '15 at 23:28
  • it gave me a permission error, but I think I just have to change permissions for that, thank you for your help! this have been marked as the answer :) – Riquelmy Melara Jan 29 '15 at 23:45
  • You are welcome! If you need assistance with the permissions, just ask – baao Jan 29 '15 at 23:46
  • Well, it looks like I do need assistance with the permission, I am using mediatemple and I am running this job with the admin user, I changed the permissions to the folder and to the file to be overwritten but I am still getting that same error. forecastrss.xml: Permission denied, any thoughts? – Riquelmy Melara Jan 30 '15 at 14:33
  • Here is the complete task 'wget http://xml.weather.yahoo.com/forecastrss?p=75039 -P /home/html/urban/wp-content/themes/canvas-child/xml/ -O forecastrss.xml' – Riquelmy Melara Jan 30 '15 at 14:35
  • can you please try it with chmod 777 -R /home/html/urban/wp-content/themes/canvas-child/xml/ @RiquelmyMelara – baao Jan 30 '15 at 14:36
  • it says Cannot write to `forecastrss?p=75039' (Permission denied). – Riquelmy Melara Jan 30 '15 at 14:49
  • strange, it's working for me. Can you please try it like this: `wget -O /home/html/urban/wp-content/themes/canvas-child/xml/forecastrss.xml http://xml.weather.yahoo.com/forecastrss?p=75039` – baao Jan 30 '15 at 15:00
  • it worked!!!! this is great! thanks a million @michael, I couldn't have made it without your help! – Riquelmy Melara Jan 30 '15 at 15:31
  • You are welcome! Good that it's working! @RiquelmyMelara – baao Jan 30 '15 at 15:32