0

I have 700 lines (string) and I was wondering how I can make a bash script that sends an HTTP request using curl when it runs the first time such that it will send the first request with the first line, then when it sends the second request it will use the second line, 3rd request, it will use the 3rd line, ..., 700th request will use the 700th line then repeat.

Also what do you think is better? Using a .csv file to read the strings from, for example:

while IFS=, read -r example
do
   ...
done < filename.csv

Or using a for-loop inside the script, for example:

arr=( "string1" "string2" "string3" .."string700" )
for i in "${arr[@]}"
do
  echo $i
done
7
  • 2
    Please clarify what your file looks like. Is it one URL per line as your text states, or is it comma separated as your script snippet seems to imply.
    – Tilman
    Commented Jan 17, 2022 at 18:09
  • Ubuntu 14.04 has passed itself End-of-life date, and is no longer supported on AskUbuntu.
    – waltinator
    Commented Jan 17, 2022 at 18:27
  • Why is PHP tagged? This question seems to want a bash script rather than a PHP script 🤔
    – matigo
    Commented Jan 17, 2022 at 22:33
  • @Tilman it is user-agents list:gist.github.com/pzb/b4b6f57144aea7827ae4 but I am going to save the file with csv extension , Yes it is one URL. Commented Jan 18, 2022 at 6:31
  • 2
    So the text file does not contain URLs at all, but User-Agent strings. And it is not comma-separated at all even though you give it the .csv extension. IFS=, does not make sense if the file isn't really comma-separated. But I see you got a valid answer, so I'll stop here.
    – Tilman
    Commented Jan 18, 2022 at 15:57

1 Answer 1

2

If you want to loop the list supplied in the comment, a newline-separated file will work fine as user-agents will not contain any newlines.

#!/bin/bash

mapfile -t < user-agents.txt
while :; do
    for agent in "${MAPFILE[@]}"; do
        curl -A "$agent" http://localhost/
        sleep 0.2
    done
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .