linux - How to parse HTTP headers using Bash? -
I need to get 2 values from the web page header which is the personal form of values I am using curls. I am able to use:
response1 = $ (curl-i -s http://www.example.com | grep http / 1.1 | awk {'print $ 2'}) Response2 = $ (curl-i -s http://www.example.com | grep server: | awk {'print $ 2'}) But I can not figure out how to Griding different values using single curl request:
response = $ (c -ai-S http://www.example.com) http_status = $ response | Grep HTTP / 1.1 | Awk {'print $ 2'} server = $ response | Grep Server: | Awk {'print $ 2'} Every attempt leads to either an error message or empty value I'm sure it's just a syntax problem.
complete bash solution awk :
See below IFS = ':' read the key values; Whitpace # trim in the "Price" value = $ {value ## + ([[space:]]}}; Value = $ {value %% + ([[space:]]) Case "server key $ server" = "$ value" ;; Content type) whistle = "$ value" ;; HTTP *) Proteo Status Read MSG & lt; & Lt; & Lt; "$ Key {$ value: +: $ value}" ;; ASAC did & lt; & Lt; (Curl-si http://www.google.com) resonance $ position counterattack $ server impedance $ whistle
build:
302 gfe / 2.0 Text / html; According to Description = UTF-8,
, the model is modeled according to the HTTP headers, which is clearly class 3.1.2:
< P> field -name should be made of printable ASCII characters (i.e., letters containing values between 33 and 126, excluding decimal, colon). Field-body can be made of any ASCII letter except CR or LF. (While CR and / or LF may be present in the actual text, they are removed from the action of the front of the field.) Therefore the above script should
Comments
Post a Comment