The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script that would check if the CD-rom is readable eamani_sun Shell Programming and Scripting 1 05-13-2008 06:54 PM
script check the users in SHELL ? anything Shell Programming and Scripting 3 02-01-2008 11:38 AM
Check EOF in shell script ideazhcy Shell Programming and Scripting 8 07-20-2007 03:29 PM
check my first shell script gridview Shell Programming and Scripting 2 05-14-2007 03:34 PM
check in unix shell script so that no one is able to run the script manually adi_bang76 Shell Programming and Scripting 1 11-16-2006 10:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-22-2008
Neil_mw Neil_mw is offline
Registered User
  
 

Join Date: Jan 2002
Location: Bristol, UK
Posts: 6
Question How do I check using shell-script if a website is available / responding?

Hi,

Could someone please help.

How do I verify using a shell script whether a website URL is available? It's roughly the URL equivalent of ping <servername> or tnsping <Oracle database name>?

I hope this is enough information - please let me know if it's not.

Many thanks,

Neil
  #2 (permalink)  
Old 07-22-2008
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,282
Use wget for example and check it's exit code which you can test while echoing $? (if it's !=0 there is probably some problem) or it's text output.
  #3 (permalink)  
Old 07-22-2008
Neil_mw Neil_mw is offline
Registered User
  
 

Join Date: Jan 2002
Location: Bristol, UK
Posts: 6
Thank-you very much indeed zaxxon. Exactly what I was after.
  #4 (permalink)  
Old 07-22-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Here is what I use, will send you an email if server is down:

On Webserver:

mystatus.cgi:
Code:
#!/usr/bin/perl
# authorized address the ip of the server getting accessing the script
$authaddress = "192.168.0.10";

# end configuration

print "Content-type: text/html\n\n";

if ($ENV{'REMOTE_ADDR'} eq "$authaddress") {

        print "I AM WORKING!";

        $uptime = open( UPTIME, "/usr/bin/uptime |" );
        while (<UPTIME>){print;}
        close( UPTIME );

}
else {print "unauthorized access";}
exit;

on other server run from cron:

servermonitor.pl:

Code:
#!/usr/bin/perl

# setup array of servers/websites to check
@sitestocheck = ('mynetworks.com','mywebsite2.com');

# the relative url of the website response script in each site
$responseprogram = "/cgi-bin/mystatus.cgi";

# path to the log file with the response data
$statusdir = "/var/log"; # needs to be 0777 web writeable

# mail feature
$mailprog ='/usr/sbin/sendmail';
$adminmail = 'me@home.com';
$frommail = 'websitemonitor@home.com';

###############################################################
# End Configuration
###############################################################

# main program
use LWP::UserAgent;


# now check each url in your array
foreach $sitetocheck (@sitestocheck){

$ua = new LWP::UserAgent;
$req = new HTTP::Request 'GET',"http://$sitetocheck$responseprogram";
$res = $ua->request($req);

if ($res->is_success) {

if ($res->content =~ /I AM WORKING/i){$response = "SERVER OK:$sitetocheck:".$res->content;}
        else {$response = "WARNING! There appears to be a problem, FIX ME!<br>\n";}
        }
        else {

        $timestamp = localtime;
        $response = "WARNING! UNABLE TO CONNECT TO $sitetocheck at $timestamp";

        $traceroute = `/usr/sbin/traceroute $sitetocheck`;
        $traceroute = "";

        }



        # write server status to the main log file
        open(FILE,">>$statusdir/statuslog.txt");
        flock(FILE, 2);
        print FILE "$response\n$traceroute\n\n";
        flock(FILE, 8);
        chmod 0777, $statusfile; # keep the file writeable

        # write to a current status file for each server or website being monitored
        open(FILE,">$statusdir/$sitetocheck");
        flock(FILE, 2);
        print FILE $response;
        flock(FILE, 8);
        chmod 0777, $statusfile; # keep the file writeable

}

        # if there is an error mail the administrator
if ($response =~ /WARNING/i){

open( MAIL, "|$mailprog -t" );

print MAIL "Subject: Server or Website Not Responding\n";
print MAIL "From: $frommail\n";
print MAIL "To: $adminmail\n";
print MAIL "Reply-to: $frommail\n\n";

      print MAIL "$response\n$traceroute";
      print MAIL "\n\n";        
      close MAIL;

}
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0