2

My curl output in console is like below. There will be many curl commands in the shell script which i will be looping through "n" times. I would like to capture/grep only those status which are not equal to 200 OK and pass it to a file. Please suggest me.

HTTP/1.1 200 OK
Authorization: Bearer 2d141ec6-1ac7-458a-96f3-318af10ae3b9

2 Answers 2

2

You can pipe curl's output to this awk:

awk '$2 != 200'

Alternatively you can use this curl command to just get status:

curl -Is -w "%{http_code}" -A "Chrome" -L "http://domain.com" -o /dev/null

To write all the URLs with non 200 in output:

url='http://domain.com/'
[[ $(curl -s -w "%{http_code}" -A "Chrome" -L "$url" -o /dev/null) != 200 ]] && echo "$url"
Sign up to request clarification or add additional context in comments.

4 Comments

my curl is like this- for ((i=1; i<=2; i++)); do curl -i -vs POST -H "$SESSION_TOKEN" -H "Accept:$ACCEPT_HEADER" "http://$BASE_URI/api/$PLATFORM/curated/featured" | awk '$2 != 200' >> RESULT.txt done >> result1.txt
This is resulting soo many other stuffs in the RESULT.txt file. I just want to have only status code in that file which is not equal to 200
In that use my 2nd suggested command that only prints status i.e. 200 or 404.
This results code 200 for everything, even links that should be 403
1

The -v option inverts the match

$ grep -v "^HTTP/1.1 200"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.