How to perform grep on curl within for loop?

后端 未结 2 1554
长发绾君心
长发绾君心 2021-01-26 04:02

I have created an array uisng the command IFS=\', \' read -r -a array <<< \"$(command)\"

The array has values:

abc001
abc002
abc003         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 04:30

    Could you please try following, not tested though should work but.

    for element in "${array[@]}"
    do
     resp=$(curl -v http://"$element":8888)
     if grep -q "Connected" "$resp"
     then
          echo resp
     fi
    done
    

    OR

    for element in "${array[@]}"
    do
     curl http://"$element":8888 -s -f -o /dev/null
     if [[ $? -eq 0 ]]
     then
          echo "url $element is working."
     fi
    done
    

提交回复
热议问题