wget to check an URL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wget to check an URL
# 1  
Old 08-18-2009
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:
Code:
[...]
while [ $rc -ne 0 ]; 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 started the site is accessible.
Now I need to do the same, but I also need to wait for server instances, which listens at same URL but different port than Server.
I can't use return code of wget because it always return 1.
If instance is up, wget responses:
Quote:
Connecting to 172.18.242.32:7001... conected.
HTTP Request sent... 404 Not Found
13:39:30 ERROR 404: Not Found.
If instance is down:
Quote:
Connecting to 172.18.242.32:7002... failed: Connection refused.
The return code is always 1 because although it was listening there is no HTML web to view as server has.
So how can I check if instance is available or not? Any other bash command to check an URL and port?

Thanks a lot and sorry for english Smilie
# 2  
Old 08-18-2009
wget only supports http and ftp protocols.
From what I understand, you want to check if each service listens to his port?
What about:
Code:
$ nmap -p[port] ip.ad.dr.ess | grep [port]

?
It outputs (with ftp service for example):
Code:
# invoke-rc.d vsftpd stop
Stopping FTP server: vsftpd.
$ nmap -p21 127.0.0.1 | grep '21'
21/tcp closed ftp

# invoke-rc.d vsftpd start
Starting FTP server: vsftpd.
$ nmap -p21 127.0.0.1 | grep '21'
21/tcp open  ftp

# 3  
Old 08-18-2009
If it's always going to return those messages, just look for "connected" or "failed" and take action appropriately.

Code:
host='172.18.242.32:7001'
result=`wget $host | head -1`

if (echo $result | grep conected 1>/dev/null 2>&1);
then
        echo success
else
        echo failure
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wget fails for a valid URL

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. ... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. Shell Programming and Scripting

Read URL data from UNIX-CLI without Wget,CURL,w3m,LWP

Hi Experts, Problem statement : We have an URL for which we need to read the data and get parsed inside the shell scripts.My Aix has very limited perl utility, i cant install any utility as well. Precisely, wget,cURL,Lynx,w3m and Lwp cant be used as i got these utilities only when i googled it.... (12 Replies)
Discussion started by: scott_cog
12 Replies

4. UNIX for Dummies Questions & Answers

Read URL data from UNIX without wget,curl,lynx,w3m.

Hi Experts, Problem statement : We have an URL for which we need to read the data and get parsed inside the shell scripts. My Aix has very limited perl utility, i cant install any utility as well. Precisely, wget,cURL,Lynx,w3m and Lwp cant be used as i got these utilities only when i googled... (0 Replies)
Discussion started by: scott_cog
0 Replies

5. UNIX for Dummies Questions & Answers

Launch a URL,validate username and password using wget or curl

Hi All, I want to launch "ex: http://gmail.com" from the cmd window and validate the credentials with username and password, is it possible? I have found something like this "wget --http-user=USER' --http-password=PASSWORD http://gmail.com" am new to this and unable to find a solution, i... (0 Replies)
Discussion started by: harsha85
0 Replies

6. Shell Programming and Scripting

Url Check for a keyword.

thanks (0 Replies)
Discussion started by: kata33
0 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

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

9. Shell Programming and Scripting

How to get the page size (of a url) using wget

Hi , I am trying to get page size of a url(e.g.,www.example.com) using wget command.Any thoughts what are the parameters i need to send with wget to get the size alone? Regards, Raj (1 Reply)
Discussion started by: rajbal
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