Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    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

    Code:
    #!/bin/sh
    $website=someurl
    lynx -dump "$website" &> /dev/null
    if [[ $? -eq 0 ]]; then
    	echo Web Page Exists
    else
    	echo Web Page Doesnt exist
    fi
    (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
    Location
    the hills
    Posts
    1,134
    If lynx won't behave, try wget.

    GNU Wget 1.13.4 Manual

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

Posting Permissions

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