DEV Community

Salad Lam
Salad Lam

Posted on

Use cases of wget

Notice

I wrote this article and was originally published on Qiita on 18 March 2023.


download files from list

assumes list.txt contains following

voice-record.mp3
agenda.docx
minutes.docx
Enter fullscreen mode Exit fullscreen mode

after executes this command

wget -i list.txt --base="http://your.site/page/"
Enter fullscreen mode Exit fullscreen mode

following files will be downloaded

http://your.site/page/voice-record.mp3
http://your.site/page/agenda.docx
http://your.site/page/minutes.docx
Enter fullscreen mode Exit fullscreen mode

add headers of http request

wget --referer="https://www.bbc.co.uk/" --header="User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0" "https://www.bbc.co.uk/weather"
Enter fullscreen mode Exit fullscreen mode

check web server is ready to serve after restart

wget -O/dev/null --timeout=5 --waitretry=15 --tries=27 --retry-connrefused --quiet "http://your.site/page"
Enter fullscreen mode Exit fullscreen mode

Options

  • -O/dev/null: saves downloaded content to /dev/null, i.e. doesn't keep
  • timeout=5: 5 seconds connection timeout
  • waitretry=15: waits up to 15 seconds in next try. By default, extra 1 second waiting time is added on next try, start from 1 second
  • tries=27: tries to connect 27 times
  • retry-connrefused: retries even though destination refuses to connect. Without apply this flag program terminates when destination refuses to connect
  • quiet: doesn't output anything to console

wget returns 0 when success, otherwise returns 4.

Top comments (0)