daily pastebin goal
8%
SHARE
TWEET

curl-post-error-detecting

tolikpunkoff Mar 29th, 2018 (edited) 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. HEADERDUMP="/tmp/headerdump.txt"
  4. SAVEFILE="/tmp/httpfile"
  5. HTTPSTATUS=""
  6.  
  7. curl -X POST "$1" -d "$2" -D $HEADERDUMP >$SAVEFILE 2>/dev/null
  8. EXITCODE=$?
  9. if [ $EXITCODE -ne 0 ]; then
  10.     echo "CURL error $EXITCODE"
  11. else
  12.     HTTPSTATUS=`cat $HEADERDUMP|head -1|awk '{print $2}'`
  13.    
  14.     if [ "$HTTPSTATUS" == "200" ];then
  15.     echo "OK"
  16.     else
  17.     echo "HTTP error $HTTPSTATUS"
  18.     fi
  19. fi
RAW Paste Data
Top