daily pastebin goal
44%
SHARE
TWEET

curl-hhtp-error-extended

tolikpunkoff Apr 3rd, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #curl HTTP status detecting (extended) example script
  4. #use exstatus <site> e.g. exstatus http://example.org/example.php
  5. #for test this script use php script
  6. #in end this file (base64 encoded)
  7.  
  8. HEADERDUMP="/tmp/headerdump.txt"
  9. SAVEFILE="/tmp/httpfile"
  10. HTTPSTATUS=""
  11. HTTPSTATUSMESS="";
  12. HTTPSTATUSID=0;
  13.  
  14. curl -o $SAVEFILE $1 -D $HEADERDUMP >/dev/null 2>/dev/null
  15. EXITCODE=$?
  16. if [ $EXITCODE -ne 0 ]; then
  17.     echo "CURL error $EXITCODE"
  18. else
  19.     HTTPSTATUS=`cat $HEADERDUMP|head -1|awk '{print $2}'` #get HTTP status code
  20.     HTTPSTATUSMESS=`cat $HEADERDUMP|head -1|cut -d ' ' -f 3-` #get HTTP status msg
  21.     HTTPSTATUSID=`echo $HTTPSTATUS|cut -c 1` #get first char status code
  22.    
  23.     case "$HTTPSTATUSID" in
  24.     1 ) echo -n "Informational: ";;
  25.     2 ) echo -n "Success: ";;
  26.     3 ) echo -n "Redirection: ";;
  27.     4 ) echo -n "Client Error: ";;
  28.     5 ) echo -n "Server Error: ";;
  29.     * ) echo -n "Unknow status: ";;
  30.     esac
  31.    
  32.     echo "$HTTPSTATUS $HTTPSTATUSMESS"
  33. fi
  34.  
  35.  
  36. #php script for test this
  37. #PD9waHANCglpbmlfc2V0KCdlcnJvcl9yZXBvcnRpbmcnLCBFX0FMTCk7DQoJaW5pX3NldC
  38. #gnZGlzcGxheV9lcnJvcnMnLCAxKTsNCglpbmlfc2V0KCdkaXNwbGF5X3N0YXJ0dXBfZXJy
  39. #b3JzJywgMSk7DQoJDQoJJGNvZGU9MDsNCglpZiAoZW1wdHkoJF9HRVQpKQ0KCXsNCgkJZW
  40. #NobyAiVXNlID9jb2RlPWh0dHBfc3RhdHVzX2NvZGUiOwkJDQoJfQ0KCWVsc2UNCgl7DQoJ
  41. #CWlmICghaXNzZXQoJF9HRVRbJ2NvZGUnXSkpDQoJCXsNCgkJCWVjaG8gIlVzZSA/Y29kZT
  42. #1odHRwX3N0YXR1c19jb2RlIjsNCgkJfQ0KCQllbHNlDQoJCXsNCgkJCSRjb2RlPSRfR0VU
  43. #Wydjb2RlJ107DQoJCQlpZiAoKCRjb2RlPDEwMCl8fCgkY29kZT41OTkpKQ0KCQkJew0KCQ
  44. #kJCWVjaG8gIldyb25nIGNvZGUgKG1pbiAxMDAsIG1heCA1OTkpIjsNCgkJCX0NCgkJCWVs
  45. #c2UNCgkJCXsNCgkJCQllY2hvICRjb2RlOw0KCQkJCWh0dHBfcmVzcG9uc2VfY29kZSgkY2
  46. #9kZSk7DQoJCQl9DQoJCX0NCgl9CQ0KPz4=
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top