Tanto quanto você precisa recuperar todos os URLs, uma maneira melhor seria usar shuf (GNU / linux coreutils) (ou sort -R
coreutils também):
shuf file | xargs wget
Arquivo:
$ cat file
"https://example.com/target1.html"
"https://example.com/target2.html"
"https://example.com/target3.html"
"https://example.com/target4.html"
man 1 shuf
NAME
shuf - generate random permutations
Novos comentários, novas necessidades, novo código:
(requerendo user-agent aleatório)
$ cat uas
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko
Código:
shuf file | while read url; do
wget --user-agent="$(shuf -n1 uas)" "$url"
done
Se preferir manter o seu caminho (um URL):
data_link=(
"https://example.com/target1.html"
"https://example.com/target2.html"
"https://example.com/target3.html"
"https://example.com/target4.html"
)
user_agent=(
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1"
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6"
"Mozilla/5.0 (Windows 7; ) Gecko/geckotrail Firefox/firefoxversion"
)
wget --user-agent="${user_agent[RANDOM % ${#user_agent[@]} ]}" "${data_link[RANDOM % ${#data_link[@]}]}"
Seu caminho para todos os URLs e user-agent (ambos randomizados):
for i in $(seq 0 $((${#data_link[@]} -1)) | shuf); do
wget -U "${user_agent[RANDOM % ${#user_agent[@]}]}" "${data_link[i]}"
done