How to check if the URL exists?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if the URL exists?
# 1  
Old 02-23-2014
How to check if the URL exists?

Hi,

I need to check if the URL exists.

Below is my OS:

Code:
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?

Last edited by mohtashims; 02-23-2014 at 04:02 AM..
# 2  
Old 02-23-2014
Just an example Try :

Code:
#!/bin/bash

url="https://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

Code:
#!/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 "https://www.unix.com"
url "http://www.unixaaaa.com"

# 3  
Old 02-23-2014
Quote:
Originally Posted by Akshay Hegde
Just an example Try :

Code:
#!/bin/bash

url="https://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

Code:
#!/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 "https://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?
# 4  
Old 02-23-2014
Did you try what I posted in message #2 ? it does your job, I guess
# 5  
Old 02-23-2014
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?
# 6  
Old 02-23-2014
repalce wget "$1" >/dev/null 2>&1with wget -q --no-check-certificate "$1" and try
Wget Error Codes:
Code:
    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.

# 7  
Old 02-23-2014
Thank you.

Last edited by mohtashims; 02-24-2014 at 05:28 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if file exists

Hi, I have the below code written. However I am not getting the desired output I am checking if the particular path has file in it. #!/bin/bash ls -l /IRS2/IRS2_ODI/INFILE/*LS* 1>/dev/null 2>/dev/null if then echo $? echo "File Exists" fi ... (3 Replies)
Discussion started by: Shanmugapriya D
3 Replies

2. Shell Programming and Scripting

Check if PID exists

In a Shell Script what is the most generic way to find in the PID exists or not. If it does not exist how can I echo the user "PID does not exist" & terminate the unix script ? If the command can work on most flavors of operating system the more useful I will find it to be. Current system... (16 Replies)
Discussion started by: mohtashims
16 Replies

3. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

4. Shell Programming and Scripting

Url Check for a keyword.

thanks (0 Replies)
Discussion started by: kata33
0 Replies

5. Shell Programming and Scripting

how to check to see if a file exists?

I want to write a script to see if various files exist. What I want to do is have the script search in various directories if a file exist, and if not, then output something like "/path/file does not exist". I don't actually know of how to check and see if a file exists or not. What I have in mind... (2 Replies)
Discussion started by: astropi
2 Replies

6. Shell Programming and Scripting

Check to see if a file exists?

Hi. I'd like to have an IF-Then-Else statement where I can check to see if a file exists? We have the Bourne Shell by default. I'm looking for the syntax to do something like this: if myfile.txt exists then ...my code else ...my code end if Any help would be greatly... (5 Replies)
Discussion started by: buechler66
5 Replies

7. Shell Programming and Scripting

ksh to check url

I have a server that keeps going down (503 Service not available). Until we find out the problem I would like to setup a simple ksh script in cron that will query url and report the status code. This way we can get someone to restart the process. Does anyone know a simple command I can call... (5 Replies)
Discussion started by: oldman2
5 Replies

8. Shell Programming and Scripting

wget to check an URL

I all, I wrote an script which starts a Weblogic server and waits until its loaded to deploy several apps. The way I checked was something like: while ; do wget --spider <URL>:<port>/console > /dev/null 2>&1 rc=$? done This works perfectly because it's an HTML site and when server is... (2 Replies)
Discussion started by: AlbertGM
2 Replies

9. Shell Programming and Scripting

Check URL with ksh

Hi everybody, I'm currently writing a ksh script which automates the entire startup of a large number of Tibco BusinessWorks domains, as well as all the deployed components running on it. My script is to be used after an infrastructure release, when the entire environement is down. It... (1 Reply)
Discussion started by: HexAnubis666
1 Replies

10. Shell Programming and Scripting

Check URL using PERL

I am trying to create a perl script that will make sure a web page can be accessed going through an Apache httpd. The actual content of the web page does not matter. Most likely the web page will just have "You have successfully reached this port." This script will eventually be running... (5 Replies)
Discussion started by: rehoboth
5 Replies
Login or Register to Ask a Question