Skip to main content
Tweeted twitter.com/StackUnix/status/973737817342971904
added 424 characters in body
Source Link

I want my machine to automatically download some files. That doesn't have to be very efficient. So I decided to do this with a bash script.

It works so far when I encode the URL hardly. But I want to get the files retrieved in irregular order and I thought I would use simple variables. How do I get the random number into my variable?

My approach

data_link0="https://example.com/target1.html"
data_link1="https://example.com/target2.html"
data_link2="https://example.com/target3.html"
data_link3="https://example.com/target4.html"

useragent0="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"
useragent1="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"
useragent3="Mozilla/5.0 (Windows 7; ) Gecko/geckotrail Firefox/firefoxversion"

wget --user-agent="$user_agent[$((RANDOM % 3))]" "$datei_link$((RANDOM % 3))"

unfortunately does not work.

I want my machine to automatically download some files. That doesn't have to be very efficient. So I decided to do this with a bash script.

It works so far when I encode the URL hardly. But I want to get the files retrieved in irregular order and I thought I would use simple variables. How do I get the random number into my variable?

My approach

data_link0="https://example.com/target1.html"
data_link1="https://example.com/target2.html"
data_link2="https://example.com/target3.html"
data_link3="https://example.com/target4.html"

wget "$datei_link$((RANDOM % 3))"

unfortunately does not work.

I want my machine to automatically download some files. That doesn't have to be very efficient. So I decided to do this with a bash script.

It works so far when I encode the URL hardly. But I want to get the files retrieved in irregular order and I thought I would use simple variables. How do I get the random number into my variable?

My approach

data_link0="https://example.com/target1.html"
data_link1="https://example.com/target2.html"
data_link2="https://example.com/target3.html"
data_link3="https://example.com/target4.html"

useragent0="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"
useragent1="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"
useragent3="Mozilla/5.0 (Windows 7; ) Gecko/geckotrail Firefox/firefoxversion"

wget --user-agent="$user_agent[$((RANDOM % 3))]" "$datei_link$((RANDOM % 3))"

unfortunately does not work.

Source Link

Generate random number after value in bash

I want my machine to automatically download some files. That doesn't have to be very efficient. So I decided to do this with a bash script.

It works so far when I encode the URL hardly. But I want to get the files retrieved in irregular order and I thought I would use simple variables. How do I get the random number into my variable?

My approach

data_link0="https://example.com/target1.html"
data_link1="https://example.com/target2.html"
data_link2="https://example.com/target3.html"
data_link3="https://example.com/target4.html"

wget "$datei_link$((RANDOM % 3))"

unfortunately does not work.