Test an url


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test an url
# 1  
Old 11-16-2004
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
# 2  
Old 11-16-2004
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.

Code:
# 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
::::::::::::::
Code:
Yahoo

::::::::::::::
mon_url.ksh
::::::::::::::
Code:
#!/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

# 3  
Old 11-16-2004
I will try it this evening.

Thank you very much

Olivier
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test the URL

Hi, As part of the requirement I need to test the one URL and whenever any click will happened on the URL it will display the message "Yes Site Looks Good " and need to capture the message and send status to email and if "Yes" will not available then need to send email with "No Site is not... (1 Reply)
Discussion started by: siva83
1 Replies

2. Shell Programming and Scripting

Reading URL using Mechanize and dump all the contents of the URL to a file

Hello, Am very new to perl , please help me here !! I need help in reading a URL from command line using PERL:: Mechanize and needs all the contents from the URL to get into a file. below is the script which i have written so far , #!/usr/bin/perl use LWP::UserAgent; use... (2 Replies)
Discussion started by: scott_cog
2 Replies

3. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

4. UNIX for Dummies Questions & Answers

Awk: print all URL addresses between iframe tags without repeating an already printed URL

Here is what I have so far: find . -name "*php*" -or -name "*htm*" | xargs grep -i iframe | awk -F'"' '/<iframe*/{gsub(/.\*iframe>/,"\"");print $2}' Here is an example content of a PHP or HTM(HTML) file: <iframe src="http://ADDRESS_1/?click=5BBB08\" width=1 height=1... (18 Replies)
Discussion started by: striker4o
18 Replies

5. Web Development

Regex to rewrite URL to another URL based on HTTP_HOST?

I am trying to find a way to test some code, but I need to rewrite a specific URL only from a specific HTTP_HOST The call goes out to http://SUB.DOMAIN.COM/showAssignment/7bde10b45efdd7a97629ef2fe01f7303/jsmodule/Nevow.Athena The ID in the middle is always random due to the cookie. I... (5 Replies)
Discussion started by: EXT3FSCK
5 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

8. UNIX for Dummies Questions & Answers

ReDirecting a URL to another URL - Linux

Hello, I need to redirect an existing URL, how can i do that? There's a current web address to a GUI that I have to redirect to another webaddress. Does anyone know how to do this? This is on Unix boxes Linux. example: https://m45.testing.address.net/host.php make it so the... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. Shell Programming and Scripting

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

10. UNIX for Advanced & Expert Users

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies
Login or Register to Ask a Question