0

I have a text file which has few Url's

salesData.txt

http://localhost:9380/run?startDate=2018-12-01&endDate=2018-12-31
http://localhost:9380/run?startDate=2018-10-01&endDate=2018-10-31
http://localhost:9380/run?startDate=2018-09-01&endDate=2018-09-30
http://localhost:9380/run?startDate=2018-08-01&endDate=2018-08-31

and a bash script as belows:

mapfile -t salesData < salesData.txt
i=0
echo 'hii'${i};     
while [ ${i} -lt ${#salesData[@]} ] ; do 
  echo "Iteration Number is " ${i} >> audit.txt
  curl -s --max-time 3600 ${salesData[${i}]}
  sleep 30
  echo "Successfully completed curl"
  ((i++))
done

This script is only running the first two curl commands and it is abruptly stopping. I am running this on a linux server by using a ssh connection to that box. How can i make sure all the curl commands get executed in sequential fashion and not just first two. I have to pull a lot bigger data which will have 12 curl commands ,i want to execute them in a sequential manner without script timing out.

Can someone please provide some guidance on this please?

1
  • I tested it even with ssh, it works as expected. Please provide the way you are invoking the script. Maybe you should do ssh -n. Mar 29, 2020 at 9:55

1 Answer 1

0

So you have a bunch of Bashism in this script. In general, its best to stick to POSIX unless its really needed. Here is example:

n1=0
while read each
do
   echo "Iteration Number is $n1" >> audio.txt
   curl -s --max-time 3600 "$each"
   n1=$(( n1 + 1 ))
done < salesData.txt
0

You must log in to answer this question.

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