Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Lightbulb Bash Script to Check for a "200 ok" http reply no longer working

    Up until recently I used this code on Centos 5 servers as part of a more complex program to determine if a URL gives a 200 OK reply (exists) or if it doesn't...

    usage: sh scriptname website

    lynx -dump "$website" &> /dev/null
    if [[ $? -eq 0 ]]; then
    	echo Web Page Exists
    	echo Web Page Doesnt exist
    (where someurl would be a proper url)

    Trying this on modern Debian 6.0 and latest Ubuntu doesn't work. It produces an output that isn't silent at all... it tries to open alternative web pages and it doesn't give a reliable response.

    What options can I use with lynx to make it work like the old lynx? and if not...

    What other methods can I use in bash to check if a URL gives a 200OK response or not?

    Any Help or Ideas are greatly appreciated...
    Last edited by expatsys; 09-22-2011 at 05:00 AM. Reason: Courtesy

  2. #2
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    the hills
    If lynx won't behave, try wget.

    GNU Wget 1.13.4 Manual

  3. #3
    I agree, wget is great for this. This is what I typically use:
    wget --timeout=1 --tries=1 --output-document=- --server-response localhost:80
    Here's some others (not as reliable but also useful):
    http_ping http://locahost:80
    httpping http://localhost:80
    nmap -n localhost -p 80

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts