windowshttpcmdwgetgrib

How to get file instead of url with wGet


I am using the following command in CMD.
wget "http://gribs2.gmn-usa.com/cgi-bin/weather_fetch.pl?parameter=wind&days=7&region=NorthEurope&dataset=nww3"

Wget download then a file with the name weather_fetch.pl@parameter=wind&days=7&region=NorthEurope&dataset=nww3.
When I'm using my webbrowser I'm getting the file _cache_weather-cache_NorthEurope.wind.7days.grb.bz2.

I need the second file, the first one is some gibberish. I tried to add the wait command but it did not work.


Solution

  • wget has a -O switch to specify the output filename.

    a so command line would be:

    wget -O _cache_weather-cache_NorthEurope.wind.7days.grb.bz2 "http://gribs2.gmn-usa.com/cgi-bin/weather_fetch.pl?parameter=wind&days=7&region=NorthEurope&dataset=nww3"
    

    That however might not always be what is needed because it is a static name and each time you download the file, the old one is replaced. So depending on the purpose of the download, you can make it more dynamic by using a batch-file and adding a date to the filename:

    @echo off
    for /f %%i in ('powershell -command Get-Date -format "yyyyMMdd"') do (
       wget -O "%%~i_cache_weather-cache_NorthEurope.wind.7days.grb.bz2" "http://gribs2.gmn-usa.com/cgi-bin/weather_fetch.pl?parameter=wind&days=7&region=NorthEurope&dataset=nww3"
    )
    

    which, considering today's date, will result in a filename of:

    20210516_cache_weather-cache_NorthEurope.wind.7days.grb.bz2