dev-resources.site
for different kinds of informations.
Getting http status in curl
Published at
5/24/2022
Categories
bash
curl
Author
Eduardo Issao Ito
How to get the http status code of curl in a script?
my_curl() {
Red='\033[0;31m'
Green='\033[0;32m'
Color_Off='\033[0m'
TEMP_FILE=$( mktemp )
trap "rm -f $TEMP_FILE" EXIT
curl -w "\n%{http_code}" -s "$@" > ${TEMP_FILE}
body=$(cat ${TEMP_FILE} | sed '$d')
status=$(cat ${TEMP_FILE} | sed -n '$p')
if [[ $status = 2* ]]; then
Color=$Green
else
Color=$Red
fi
echo -e "${Color}Status: $status${Color_Off}"
echo $body
}
my_curl -X GET http://jservice.io/api/random
Articles
12 articles in total
Resumo Kubernetes
read article
Check for newer versions of dependencies in pom.xml
read article
Changing the JVM in spring-boot:build-image
read article
Changing the base Linux image in spring-boot:build-image
read article
Custom Root CA in spring-boot:build-image
read article
Getting http status in curl
currently reading
DB2 backup/restore schema
read article
Using MTLS
read article
Convert OpenAPI spec to JSON Schema
read article
Json validation with OpenAPI Schema
read article
SFTP server in Ubuntu
read article
Using multiple JMS servers with Spring Boot
read article
Featured ones: