shell script to execute requests in a loop

Create exam.sh file

#!/bin/bash
m=0
cat parameter.txt | while read rows
do
  m=`expr $m + 1`  
  echo "$m---"
  curl --connect-timeout 10 -X POST -H "Content-type: application/json" -d "$rows" http://ip:port/test/api
  printf "\n"
  sleep 1s
done

Create parameter.sh file

{"id":"1","user":"test1"}
{"id":"2","user":"test2"}
{"id":"3","user":"test3"}

The optional parameter '--connect-timeout' can be used to set the wait time in seconds.

报错:/bin/bash^M: bad interpreter: No such file or directory

The script file has been edited under windows, the end of each line under windows is \n\r, and the end of the file under linux is \n

Solve
sed -i 's/\r$//' example.sh

sed -i 's/\r$//' parameter.txt

Guess you like

Origin blog.csdn.net/wyyother1/article/details/130806015