Linux script with curl to check webservice is up

后端 未结 6 836
难免孤独
难免孤独 2021-01-30 17:05

I have a webservice provided at http://localhost/test/testweb

I want to write a script to check if webservice is up with curl

If there a curl parame

6条回答
  •  無奈伤痛
    2021-01-30 17:31

    Same as @burhan-khalid, but added --connect-timeout 3 and --max-time 5.

    test_command='curl -sL \
        -w "%{http_code}\\n" \
        "http://www.google.com:8080/" \
        -o /dev/null \
        --connect-timeout 3 \
        --max-time 5'
    if [ $(test_command) == "200" ] ; 
    then
       echo "OK" ;
    else
       echo "KO" ;
    fi
    

提交回复
热议问题