wget link 从文件中的随机行

wget link from random line in file

我正在尝试下载一个使用半可预测 urls 的网站,这意味着 url 将始终以随机的五个字符的字母数字字符串结尾。我使用以下命令创建了一个带有随机字符串的紧缩文件:

crunch 5 5 abcdefghijklmnopqrstuvwxyz123456789 > possible_links

然后我创建了一个 bash 文件来调用这些行并获取链接:

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

但显然它会转到 aaaaa,然后是 aaaab,然后是 aaaac,aaaad 等等,有没有办法让它转到随机行?

使用mktemp --dry-run选项:

#!/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

一般解(对于n个随机字符)

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