2

Can anyone explain me the below curl command and how it works :

STATUS_CODE=`curl –output /dev/null –silent –head –write-out ‘%{http_code}\n’ $next` # If you want to set a timeout then add –max-time 15, here 15 is 15seconds 

    1 Answer 1

    3

    You seem to be missing a few double dashes, probably the result of copy and paste:

    STATUS_CODE=`curl --output /dev/null --silent --head --write-out ‘%{http_code}\n’ $next` 

    Assuming that you call this with next being a url (e.g. in a loop or reading from a file):

    • --output /dev/null discards the normal output
    • --silent suppresses the progress meter
    • --head fetch header only
    • --write-out '%{http_code}\n' prints the status code

    So in the end the status of the URL request ends up in STATUS_CODE

    (And if you want to set the timeout, then use double dashes too: --max-time).

    1
    • Hi Anthon, I have tried the same command but it's returning the error code as "302". what does it mean ?? Also does the curl command work in the same manner for https as it work for http.CommentedJul 2, 2013 at 8:44

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.