Advertisement
tolikpunkoff

404-curl-web-error-detecting

Mar 21st, 2018
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #curl HTTP error detecting
  4. #Using examples:
  5. #./404 ttp://tolik-punkoff.com/net-takoj-stranicy
  6. #CURL error 1
  7. #./404 http://tolik-punkoff.com/net-takoj-stranicy
  8. #HTTP error 404
  9. #./404 http://tolik-punkoff.com/scripts/ip/ip61.php
  10. #OK
  11.  
  12.  
  13. HEADERDUMP="/tmp/headerdump.txt"
  14. SAVEFILE="/tmp/httpfile"
  15. HTTPSTATUS=""
  16.  
  17. curl -o $SAVEFILE $1 -D $HEADERDUMP >/dev/null 2>/dev/null
  18. EXITCODE=$?
  19. if [ $EXITCODE -ne 0 ]; then
  20.     echo "CURL error $EXITCODE"
  21. else
  22.     HTTPSTATUS=`cat $HEADERDUMP|head -1|awk '{print $2}'`
  23.    
  24.     if [ "$HTTPSTATUS" == "200" ];then
  25.     echo "OK"
  26.     else
  27.     echo "HTTP error $HTTPSTATUS"
  28.     fi
  29. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement