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... :confused:

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

please help

Which shell is this? Apart from using endif instead of fi the syntax isn't technically wrong for Bourne shell, but definitely ... eerie.

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

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

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

or

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

using ping is a bad idea ...
use wget,
check out wget man page for the timeout values, and other tuning options.

Try this link: How do I check using shell-script if a website is available / responding?

big thanx, ill see on monday. big big thanx

#!/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

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 :wink: and ping goes only to the router... and this PC/server is under 2 routers. big thanx for help to you all

Try this one:

if ! ping -c 1 yourhost | grep 'bytes from' > /dev/null
then
echo mail command here...
fi

--
Fabio Berbert de Paula
Viva o Linux - A maior comunidade de usu�rios Linux do Brasil!