0

I am writing a plugin and I want to extract a status code from my curl request:

curl -I localhost | grep HTTP;

Right now I have

% Total    % Received % Xferd  Average Speed   Time    Time     Time  
Current
                             Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
HTTP/1.1 302 Found

as an output but I need only 302

0

@Dmitrii you can use some options of curl to do this.

example:

ip-10-0-8-8:~ tien$ curl -s -o /dev/null -w "%{http_code}\n" https://example.com
200

-s means silent or quiet mode. Don't show progress meter or error messages.
-w makes curl display information on stdout after a competed transfer.
-o wrties output to file instead of stdout.

and \n adds a new line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.