Advertisement
tolikpunkoff

curl-post-error-detecting

Mar 29th, 2018
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement