Test an url

Hy all,

(sorry in advance for my bad english)

i have a problem with a web application who seems to "freeze", and i want to make a little unix script for checking the application.

Does anyone know a command to test an url ??? the application is on a server where i can not install anything.

Thanks in advance,

Olivier

I hope this is useful....
I wrote a Java class "establishURLConnection.java" that takes URL as 1st 1 arg.

Use "mon_url.ksh" as a cronjob, "mon_url.dat" as a list of URL to monitor.

# more establishURLConnection.java
//------------------------------------------------------------//
//  establishURLConnection.java:                             //
//------------------------------------------------------------//
//  Created: Steven Koh on Aug 14th 2003
//  Last Amended: Steven Koh on Aug 14th 2003
//  Last checked: Steven Koh on xxx
//------------------------------------------------------------//

import java.io.*;
import java.net.*;
import java.util.Date;
import java.text.SimpleDateFormat;

public class establishURLConnection {

   public static void main (String[] args) {

      URL u;
      InputStream is = null;
      DataInputStream dis = null;
      String s;
      String loginAdd=args[0];

      long startMS, endMS, timeTaken;

      Date dateTime=new Date();
      String plotTime=new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").format(dateTime);

      try {
         //Start Connection: Login
         u = new URL(loginAdd);
         is = u.openStream();         // throws an IOException
         dis = new DataInputStream(new BufferedInputStream(is));

         //For Debugging
         //while ((s = dis.readLine()) != null) {  System.out.println(s); }

      } catch (MalformedURLException mue) {

         System.out.println(plotTime + " MalformedURLException happened at " + loginAdd);
         //mue.printStackTrace();
         System.exit(1);

      } catch (IOException ioe) {

         System.out.println(plotTime + " IOException happened at " + loginAdd);
         //ioe.printStackTrace();
         System.exit(1);

      } finally {
         try                     {   dis.close();   is.close();   }
         catch (IOException ioe) {                 }
      } // end of 'finally' clause

   }  // end of main

} // end of class definition

::::::::::::::
mon_url.dat
::::::::::::::

Yahoo

::::::::::::::
mon_url.ksh
::::::::::::::

#!/bin/ksh

# Created: Steven Koh on Jul 5th 2003
# Last Amended: Steven Koh on Jul 5th 2003
# Last checked: Steven Koh on xxx
#
# Monitor URL Script
# Purpose: Monitors URL via use of Java, HTTP
# and notifies via email.
# Usage: Execute from crontab every 15 minutes.
# Dependencies: $HOME/mon_url.dat, JavaPkg:/usr/local/scripts/MyJavaMod
# Outputs: E-mail
#***************************************************

# The next variable can be set for multiple addresses
# (i.e. xyz@modus.com,abc@modus.com)
MAILADD=$LOGNAME@localhost
SMS_LIST=$HOME/sms.List

CONF_FILE=/usr/local/scripts/monitor.conf

# Define the hostname of the SNMP server
SNMP_SRV=`grep "SNMP_SRV" $CONF_FILE | awk -F= '{print $NF}'`
SEND_TRAP=`grep "SEND_TRAP" $CONF_FILE | awk -F= '{print $NF}'`
SEND_SMS=`grep "SEND_SMS" $CONF_FILE | awk -F= '{print $NF}'`

javaPkg=/usr/local/scripts/MyJavaMod

cd $javaPkg

grep -v "#" $HOME/mon_url.dat |
while read -r URL
do
if test `/usr/bin/java establishURLConnection $URL | wc -l` -ne 0; then

    # Wait 5 minutes before checking again
    sleep 300

    if test `/usr/bin/java establishURLConnection $URL | wc -l` -ne 0; then

         mail $MAILADD <<EOF
From: $0
To: $MAILADD
Subject: $URL Down

$URL is not responding.

EOF

# Sending SMS
$SEND_SMS $SMS_LIST "URL001_$URL: No reply from $URL. Check if $URL/network is down"

    fi
fi

done

I will try it this evening.

Thank you very much

Olivier