Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget - only output redirect url but no download

Tags:

wget

I have a download link to a large file. You need to be logged in to the site, so a cookie is used. The download link redirects to another URL. I'm able to download the file with wget but I only want the output of the "real" direct download link. wget does exactly this before starting the download

Location: https://foo.com/bar.zip [following]

Is there a way to make wget stop and not actually downloading the file? The solutions I found recommend redirecting to dev/null but this would still download the file. What I want is wget following the redirects but not actually starting the download.

like image 744
Menacer Avatar asked Oct 18 '25 14:10

Menacer


2 Answers

I couldn't find a way to do it with wget, but I found a way to do it with curl:

curl https://openlibrary.org/data/ol_dump_latest.txt.gz -s -L -I -o /dev/null -w '%{url_effective}'

This only downloads the HEAD of the page (and sends it to /dev/null), so the file itself is never downloaded.

(src: https://stackoverflow.com/a/5300429/2317712 )

like image 125
cdrini Avatar answered Oct 21 '25 13:10

cdrini


Going off of @qqilihq's comment to the curl answer, this will first strip out the line starting with "Location:" then remove the "Location: " from the beginning and the " [following]" from the end using awk. Not sure if I would use this as it looks like a small change in the wget output could make it blow up. I would use the curl answer myself.

wget --max-redirect=0 http://example.com/link-to-get-redirec-url-from 2>&1 | awk '/Location: /,// { print }' | awk '{print $2}'

like image 36
frederickjh Avatar answered Oct 21 '25 12:10

frederickjh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!