The UNIX and Linux Forums  


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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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