From owner-freebsd-questions@FreeBSD.ORG Wed Dec 14 11:43:45 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 77C0116A41F for ; Wed, 14 Dec 2005 11:43:45 +0000 (GMT) (envelope-from xfb52@dial.pipex.com) Received: from smtp-out6.blueyonder.co.uk (smtp-out6.blueyonder.co.uk [195.188.213.9]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0DBBE43D5C for ; Wed, 14 Dec 2005 11:43:32 +0000 (GMT) (envelope-from xfb52@dial.pipex.com) Received: from [82.41.32.173] ([82.41.32.173]) by smtp-out6.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Wed, 14 Dec 2005 11:44:25 +0000 Message-ID: <43A00560.4060500@dial.pipex.com> Date: Wed, 14 Dec 2005 11:43:28 +0000 From: Alex Zbyslaw User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-GB; rv:1.7.12) Gecko/20051106 X-Accept-Language: en MIME-Version: 1.0 To: Anirban Adhikary References: <71c73b070512132244y1d8737ebhe32be069976add88@mail.gmail.com> In-Reply-To: <71c73b070512132244y1d8737ebhe32be069976add88@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 14 Dec 2005 11:44:25.0263 (UTC) FILETIME=[BB8913F0:01C600A3] Cc: freebsd-questions@freebsd.org Subject: Re: doubts 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: Wed, 14 Dec 2005 11:43:45 -0000 Anirban Adhikary wrote: >Hi guys >This is Anirban. I have a doubts on the following question. > >How to write a shell program that will check whether a server is up or down >(on ping) and log the report to a file. > > You may be wondering why no-one is replying to you and the main reasons would be: 1) You show no evidence of even having *tried* to write something. If you'd said "I did X but it didn't work" then maybe some kind soul would have helped you out. All you are asking is for someone else to write your script for you. 2) It's pretty clear that you know next to nothing about shell scripting, in which case you should do what everyone else who has needed to write shell scripts has done: a) Buy a book or b) study some examples of which there must be hundreds on your FreeBSD installation or c) get someone to teach you or d) search google for tutorials And always, always, always read the manual pages. Here's a quick sh script for you. You can figure out how to do the redirection and how to run it from cron. $ for host in host1 host2 > do > if ping -c 1 $host 2>&1 > /dev/null > then > echo $host: UP > else > echo $host: DOWN > fi > done host1: DOWN host2: UP You might also consider nagios from the ports but it may be far more than you want. With the limited information you provided about why you want to do this, no-one will ever know. --Alex