Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Created June 24, 2014 05:50
Show Gist options
  • Save jmakeig/4a60ddd38647078f5e32 to your computer and use it in GitHub Desktop.
Save jmakeig/4a60ddd38647078f5e32 to your computer and use it in GitHub Desktop.
Capture 4xx and 5xx errors as errors with cURL
#! /bin/bash
# --fail: exit with 22 for an HTTP error response
# --show-error: write a message to stderr on failure, even with --silent
# --silent: don't show progress or errors
# -i: include headers in output
curl --fail --show-error --silent -i http://httpstat.us/"$1" 1>/dev/null
if [[ $? != 0 ]] ; then
echo "error"
exit 1
fi
echo "worked"
@leiless
Copy link

leiless commented Feb 10, 2022

Short for curl -fSsi http://httpstat.us/200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment