简体   繁体   中英

wget link from random line in file

I'm trying to download a website that uses semi-predictable urls, meaning the url will always end with a random five character alphanumeric string. I created a file with crunch with the random string by using the command:

crunch 5 5 abcdefghijklmnopqrstuvwxyz123456789 > possible_links

Then I created a bash file to call the lines and wget the links:

#!/bin/bash
FILE=possible_links
while read line; do
        wget -q --wait=20 www.ghostbin.com/paste/${line}
done < $FILE

but obviously it is going to go to aaaaa, then aaaab, then aaaac, aaaad, etc etc, is there a way to make it go to random lines?

Use mktemp --dry-run option :

#!/bin/bash
while true # or specify a count using something like while [ $count -le 20 ]
do
rand_str="$(mktemp --dry-run XXXXX)" # 5 Xs for five random characters
  wget -q --wait=20 www.ghostbin.com/paste/${rand_str}
# if you use count increment count ie do '((count++))' else you get infinite loop
done

General solution (for n random characters)

str=$(printf "%-10s" "X") # here n=10
while condition
do
rand_str=$(mktemp --dry-run ${str// /X}) 
.
.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM