I have a list of URL and I'm trying construct a firewall log with that list. Example:
$ cat urls.csv
a.com
I know how to construct the log with IP directly mentioned as variable.
$ cat processor.sh
#!/bin/bash
filename="$1"
while read -r line
do
URLS="$line"
IP='10.109.1.1'
today_date=`date +%d/%b/%Y`
conact_1=" - - ["
concat_2=":00:00:00 +0000] "
date_concat=$conact_1$today_date$concat_2
GET='"GET '
protocol=' HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0'
final_url=$IP$conact_1$today_date$concat_2$GET$URLS$protocol
echo $final_url
done < "$filename"
Result:
$ bash processor.sh urls.csv
10.109.1.1 - - [22/Jul/2018:00:00:00 +0000] "GET a.com HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0
Now If i have a log line of 50 or 100 or even more , How can I generate random IP for the total number of URLs and generate a log line ?
$cat urls.csv
a.com
b.com
c.com
d.com
....
Any suggestions on how to generate random IPs in bash?
Expected Result:
$ bash processor.sh urls.csv
1.1.1.1 - - [22/Jul/2018:00:00:00 +0000] "GET a.com HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0
1.1.1.2 - - [22/Jul/2018:00:00:00 +0000] "GET b.com HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0
1.1.1.3 - - [22/Jul/2018:00:00:00 +0000] "GET c.com HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0
1.1.1.4 - - [22/Jul/2018:00:00:00 +0000] "GET d.com HTTP/1.1" 304 0 304 0 0 0 655 456 645 368 0
............
date_concat=$(date +" - - [%d/%b/%Y:00:00:00 +0000] "); the format string isn't restricted to the special escape characters.