WGET. Лучшие практики использования

wget

Загрузка всех URL, указанных в файле FILE:

$ wget -i FILE

Скачивание файла в указанный каталог (-P):

$ wget -P /path/for/save ftp://ftp.example.org/some_file.iso

Использование имя пользователя и пароля на FTP/HTTP:

$ wget ftp://login:password@ftp.example.org/some_file.iso
$ wget --user=login --password=password ftp://ftp.example.org/some_file.iso

Скачивание в фоновом режиме (-b):

$ wget -b ftp://ftp.example.org/some_file.iso

Продолжить (-c continue) загрузку ранее не полностью загруженного файла:

$ wget -c http://example.org/file.iso

Скачать страницу с глубиной следования 10, записывая протокол в файл log:

$ wget -r -l 10 http://example.org/ -o log

Скачать содержимое каталога http://example.org/~luzer/my-archive/ и всех его подкаталогов, при этом не поднимаясь по иерархии каталогов выше:

$ wget -r --no-parent http://example.org/~luzer/my-archive/

Для того, чтобы во всех скачанных страницах ссылки преобразовывались в относительные для локального просмотра, необходимо использовать ключ -k:

$ wget -r -l 10 -k http://example.org/

Также поддерживается идентификация на сервере:

$ wget --save-cookies cookies.txt \
  --post-data 'user=foo&password=bar' \
  http://example.org/auth.php

Скопировать весь сайт целиком:

$ wget -r -l 0 -k http://example.org/

Скачивание галереи картинок с превьюшками.

$ wget -r -k -p -l1 -I /images/ -I /thumb/ \
  --execute robots=off www.example.com/gallery.html

Сохранить веб страницу (как она открывается локально) в текущую директорию

$ (cd cli && wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html)

Продолжить скачивание частично скаченного файла

$ wget -c http://www.example.com/large.file

Скачать множество файлов в текущую директорию

$ wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/

Отображать вывод напрямую (на экран)

$ wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' | head

Скачать url в 01:00 в текущую директорию

$ echo 'wget url' | at 01:00

Сделать закачку с уменьшенной скоростью В данном случае 20 КB/s

$ wget --limit-rate=20k url

Проверить ссылки в файле

$ wget -nv --spider --force-html -i bookmarks.html

Оперативно обновлять локальную копию сайта (удобно использовать с cron)

$ wget --mirror http://www.example.com/

Используем wildcard для того чтобы скачать несколько страниц

$ wget http://site.com/?thread={1..100}
$ wget http://site.com/files/main.{css,js}

Запустить скачивание списка ссылок в 5 потоков

$ cat links.txt | xargs -P 5 wget {}

Проверить ссылки из файла на живость

$ cat list.txt
http://yandex.ru
http://google.ru
http://yandex.ru/qweqweqweqwe
$ wget -nv  --spider -i list.txt
2013-08-08 22:40:20 URL: http://www.yandex.ru/ 200 Ok
2013-08-08 22:40:20 URL: http://www.google.ru/ 200 OK
http://yandex.ru/qweqweqweqwe:
Удалённый файл не существует — битая ссылка!

Источники:

Test Internet Connection Speed From Console Over SSH Command Line

aptestI have recently rented a dedicated server for my hobby projects and learning CentOS Linux server. I was informed that I am connected to the 100M/s port. How do I test my Internet connection download speed from the console over the ssh session without using HTML5 or Adobe flash/Java applets based websites? How do I test my upload speed from the console?

I recommend that you use lftp command to test Internet upload and download speed from console. You can run lftp using the ssh client:

[a] wget — Retrieves files from the web (download speed test).

[b] wput — A tiny wget-like ftp-client for uploading files (upload speed test).

[c] axel — Another light download accelerator.

[d] iperf — Perform network throughput tests.

Installation

You can use the following yum command to install lftp and iperf under RHEL / CentOS / Fedora Linux:

# yum install lftp iperf

OR use the following apt-get command under Debian or Ubuntu Linux:

$ sudo apt-get install lftp iperf

Step #1: Find out download url

You need a large size file to test download speed. For example, you can visit the home page of«Argonne National Laboratory Public Software Mirror» to grab Centos Linux ISO file.

Step #2: Use lftp command to test download speed

The syntax is:

lftp -e 'pget http://example.com/file.iso; exit; '
lftp -e 'pget http://speedtest.example.com/500M.bin; exit; '
lftp -e 'pget http://mirror.anl.gov/pub/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso; exit; '

Sample outputs:

Fig.01: lftp testing internet speed
You will also get the report as follows:

725617504 bytes transferred in 65 seconds (10.63M/s)

A note about wget command

You can use the wget command as follows for testing download speed:

$ wget -O /dev/null http://mirror.anl.gov/pub/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso

Sample outputs:

Fig.02: wget command in action

Step #3: Use lftp command to test upload speed
The sytnax is as follows:

lftp -u userName ftp.example.com -e 'put largecd1.avi; bye'
lftp -u userName,passWord ftp.example.com -e 'put largecd1.avi; bye'
lftp -u userName,passWord ftp.example.com -e 'put /path/to/large.iso; bye'

In this example, I am uploading a file to my private ftp server:

lftp -u admin homeserver -e 'cd video; put /home/vivek/Downloads/debian-testing-amd64-CD-1.iso; bye'

OR

lftp -u admin homeserver.public.ip.here -e 'cd video; put /home/vivek/Downloads/debian-testing-amd64-CD-1.iso; bye'

Sample outputs:

Fig.03: lftp upload speed test in action

How do I test network throughput rate between two Linux or Unix servers?
Consider the following setup:

+------------------+                            +----------------+
| Linux server A    +------- ISP Internet-------+ Linux server B +
+------------------+                            +----------------+
IP:202.54.1.1                                     IP:203.54.1.1
iperf server                                      iperf client

Iperf is a tool to measure maximum TCP bandwidth, allowing the tuning of various parameters and UDP characteristics. Iperf reports bandwidth, delay jitter, datagram loss. On server A start iperf as follows:

# iperf -s -B 202.54.1.1

On server B type the same command as follows:

# iperf -c 202.54.1.1 -d -t 60 -i 10

Sample outputs:

Fig.04: iperf client in action
Where,

  1. -s : Run in server mode.
  2. -B IP : Bind to IP, an interface or multicast address.
  3. -c IP : Run in client mode, connecting to IP.
  4. -d : Do a bidirectional test simultaneously.
  5. -t 60 : Time in seconds to transmit for (default 10).
  6. -i 10 : Pause n seconds between periodic bandwidth reports.

RECOMMENDED READINGS
See the following man pages for information:

man lftp
man wget
man iperf