How to Request a File But Not Save It with Wget

How do I request a file but not save it with Wget?

Use q flag for quiet mode, and tell wget to output to stdout with O- (uppercase o) and redirect to /dev/null to discard the output:

wget -qO- $url &> /dev/null

> redirects application output (to a file). if > is preceded by ampersand, shell redirects all outputs (error and normal) to the file right of >. If you don't specify ampersand, then only normal output is redirected.

./app &>  file # redirect error and standard output to file
./app > file # redirect standard output to file
./app 2> file # redirect error output to file

if file is /dev/null then all is discarded.

This works as well, and simpler:

wget -O/dev/null -q $url

Is there a curl/wget option that prevents saving files in case of http errors?

One liner I just setup for this very purpose:

(works only with a single file, might be useful for others)

A=$$; ( wget -q "http://foo.com/pipo.txt" -O $A.d && mv $A.d pipo.txt ) || (rm $A.d; echo "Removing temp file")

This will attempt to download the file from the remote Host. If there is an Error, the file is not kept. In all other cases, it's kept and renamed.

wget command to download a file and save as a different filename

Use the -O file option.

E.g.

wget google.com
...
16:07:52 (538.47 MB/s) - `index.html' saved [10728]

vs.

wget -O foo.html google.com
...
16:08:00 (1.57 MB/s) - `foo.html' saved [10728]

How to get wget only save file if its complete

What about this bash script:

#!/bin/bash
if wget http://www.example.com/mysql.zip -O mysql.zip
then
# Do something with file
else
rm mysql.zip
fi

How to get file instead of url with wGet

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®ion=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®ion=NorthEurope&dataset=nww3"
)

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

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

wget - if requested file is 0kb or connection timed out then do not save file

i solved with a script on linux which is deleting 0kb files.

    find . -maxdepth 1 -size 0 -exec rm {} \;


Related Topics



Leave a reply



Submit