The UNIX and Linux Forums  


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
How do I check using shell-script if a website is available / responding? Neil_mw Shell Programming and Scripting 3 07-22-2008 12:38 PM
Script to check processes and send an email heprox Shell Programming and Scripting 1 11-06-2006 01:17 AM
check the status and send an email with status isingh786 Shell Programming and Scripting 3 12-29-2005 07:22 PM
Send email where # is in the email address - Using Unix jingi1234 UNIX for Dummies Questions & Answers 1 05-23-2005 12:23 PM
Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win) Vetrivela UNIX for Advanced & Expert Users 2 02-15-2005 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 08-29-2008
big_nobody big_nobody is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
Question HELP: check if website is on, if not email

if {ping -c 1 www || { "Destination Host Unreachable" ; }}
then
{ echo "neveikia senas-pastas, web serveris" | mailx -s "Senas web serveris" mail }
endif;
this is my script but it does not work...

this script will be used to check if website is online if not then sends an email...

please help

Last edited by big_nobody; 08-29-2008 at 10:40 AM..
  #2 (permalink)  
Old 08-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Which shell is this? Apart from using endif instead of fi the syntax isn't technically wrong for Bourne shell, but definitely ... eerie.


Code:
if ! ping -c 1 www; then
  mailx -s subject mail <<__HERE
Body of email message
__HERE
fi

This can be shortened to the slightly more obscure


Code:
ping -c 1 www ||   mailx -s subject mail <<__HERE
Body of email message
__HERE

If you specifically want to look for "Destination host unreachable" (which I do not recommend at all) the syntax for that would be something like


Code:
case `ping -c 1 www` in *"Destination host unreachable"*) mailx ... ;; esac

or


Code:
if ping -c 1 www 2>&1 | grep "Destination host unreachable" >/dev/null; then
  mailx ...
fi

  #3 (permalink)  
Old 08-29-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
using ping is a bad idea ...
use wget,
check out wget man page for the timeout values, and other tuning options.
  #4 (permalink)  
Old 08-29-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Try this link: How do I check using shell-script if a website is available / responding?
  #5 (permalink)  
Old 08-29-2008
big_nobody big_nobody is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
big thanx, ill see on monday. big big thanx
  #6 (permalink)  
Old 09-01-2008
big_nobody big_nobody is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
#!/bin/bash
wget -t 1 WWW
if [ -f index.html ]
then
rm -rvf index.html
else
echo "does not work website in old-server" | mailx -s "Server named old-server does not work" user@host
fi

Last edited by big_nobody; 09-01-2008 at 06:06 PM.. Reason: hide website and email (security)
  #7 (permalink)  
Old 09-01-2008
big_nobody big_nobody is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 4
i used this script, because i need to know if PC is available... if server gives some error generated in index.html it is good, because on this PC are about 20 virtual sites in apache. if one is down others are in use and ping goes only to the router... and this PC/server is under 2 routers. big thanx for help to you all
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 07:34 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