티스토리 뷰

공부

[sh] http status code

승가비 2023. 7. 6. 19:44
728x90
STATUS=$(curl -o /dev/null -w "%{http_code}" "https://blog.leocat.kr/")

if [ $STATUS -eq 200 ]; then
  echo "OKOK"
fi

https://blog.leocat.kr/notes/2018/08/03/shell-fetch-http-status-code-from-curl-result

 

[Shell] curl로 호출하고 HTTP status code 확인하기

curl로 URL을 호출한 뒤 HTTP status code를 확인하고 싶다면, -w 옵션으로 찍어보면 된다. curl man page를 보면 아래와 같이 curl의 stdout 출력 이후에 -w 옵션으로 적어준 내용이 출력된다고 적혀 있다.

blog.leocat.kr

 

728x90
댓글