Tuesday, October 25, 2022

[SOLVED] Can I mute the output of the curl command in the bash script below?

Issue

I am attempting to check if a connection can be made with the url in the script, not sure if that is the best approach. The curl command's output is all going to stdout. I only want my echo to go to stdout after running the script below. I tried adding -s, but that did not help. I would appreciate some help.

check=$(curl -s -vv -I https://github.com | grep "HTTP/2 200")
if [[ -z "$check" ]]; then
  echo "Cnxn failed"
else
  echo "Cnxn successful"
fi

I would like to see something like this only:

Cnxn failed

or

Cnxn successful

Solution

Please try this code

check=$(curl -s -vv -I https://github.com 2>/dev/null | grep "HTTP/2 200")
#echo $check
if [[ -z $check ]] ; then
      echo "Cnxn failed"
    else
      echo "Cnxn successful"
fi


Answered By - Aleksandr Pakhomov
Answer Checked By - Candace Johnson (WPSolving Volunteer)