Search code examples
cronyahoo-weather-api

Download online XML file using cron


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.


Solution

  • 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/