From owner-freebsd-questions@FreeBSD.ORG Fri Dec 16 07:51:28 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DDFC016A41F for ; Fri, 16 Dec 2005 07:51:28 +0000 (GMT) (envelope-from hde@daden.net) Received: from mail.ruder.net (216-166-252-178.dsl.peknil.grics.net [216.166.252.178]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6A75F43D5A for ; Fri, 16 Dec 2005 07:51:27 +0000 (GMT) (envelope-from hde@daden.net) Received: from 12.203.202.40 ([12.203.202.40]) by mail.ruder.net ([192.168.10.10]) with Microsoft Exchange Server HTTP-DAV ; Fri, 16 Dec 2005 07:51:22 +0000 Received: from devilBSD.freeBSD by mail.daden.net; 16 Dec 2005 01:51:22 -0600 From: "Harley D. Eades III" To: Anirban Adhikary In-Reply-To: <71c73b070512152153h507fae3eo22e3b2d52df1202f@mail.gmail.com> References: <71c73b070512152153h507fae3eo22e3b2d52df1202f@mail.gmail.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Fri, 16 Dec 2005 01:51:22 -0600 Message-Id: <1134719482.34653.30.camel@devilBSD.freeBSD> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 FreeBSD GNOME Team Port Cc: freebsd-questions@freebsd.org Subject: Re: shell script doesnot executing X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2005 07:51:29 -0000 On Fri, 2005-12-16 at 11:23 +0530, Anirban Adhikary wrote: > Hi guys > This is Anirban here. I have the problem again with the previous shell > script.Which was > Write a shell script that will check whether a server is up or not(on ping) > & log the report to a file. > > I have tried to write the program in the following way > > #! /bin/sh > echo -n "Enter the IP or Hostname of the Server" > read host > #echo $host > ping -c2 $host &>file2 > if [ $? = 0 ];then The problem is you're checking the exit status of ping, even if the host is down ping is exiting with a successful status. You need to use sed or awk or something similiar to test for replys. -- Harley -----BEGIN GEEK CODE BLOCK----- G: GCS-- d- a? C++++ B- E+++ W+++ N++ w--- X+++ b++ G e* r x+ z+++++ ------END GEEK CODE BLOCK------