How to check if the URL exists?

Hi,

I need to check if the URL exists.

Below is my OS:

SunOS mymac1 Generic_148888-04 sun4v sparc SUNW,SPARC-Enterprise-T5220

I do not have the curl set in the profile nor am i aware about its path.

But i have wget . Please help me with params for the same.

Can you help me check if the URL exists from unix shell script?

Just an example Try :

#!/bin/bash

url="http://www.unix.com"

if wget $url >/dev/null 2>&1 ; then
	echo "Url : $url exists..."
else
	echo "Url : $url doesn't exists.."
fi

url="http://www.unixaaaa.com"

if wget $url >/dev/null 2>&1 ; then
	echo "Url : $url exists..."
else
	echo "Url : $url doesn't exists.."
fi

---------- Post updated at 02:47 PM ---------- Previous update was at 02:40 PM ----------

You can create function something like this and call

#!/bin/bash



url(){
	if [ ! -z "$1" ]; then
		wget "$1" >/dev/null 2>&1 
		[ "$?" -eq 0 ] && echo "Url : $1 exists..." || echo "Url : $1 doesn't exists.."
	else
		echo "No Arguments..exiting" & exit
	fi
}


url "http://www.unix.com"
url "http://www.unixaaaa.com"

URL=https://mybank.net:8443/Services/com/Notification.jws

This only checks for the hostname / port number [https://mybank.net:8443]. What about the rest of the URL / page [/Services/com/Notification.jws] if it exists or not?

How can we check that?

Did you try what I posted in message #2 ? it does your job, I guess

I have a https url which does exist.

$? returns 5 with wget

Using your code it says "URL DOES NOT EXIST"

The URL is internal to our network so u cant access it but the server running the script can

Why is this the problem?

repalce wget "$1" >/dev/null 2>&1 with wget -q --no-check-certificate "$1" and try
Wget Error Codes:

    0 No problems occurred.
    1 Generic error code.
    2 Parse error�for instance, when parsing command-line options, the .wgetrc or .netrc�
    3 File I/O error.
    4 Network failure.
    5 SSL verification failure.
    6 Username/password authentication failure.
    7 Protocol errors.
    8 Server issued an error response.

Thank you.