Date: Fri, 16 Dec 2005 02:10:54 -0600 From: "Harley D. Eades III" <hde@foobar-qux.org> To: Anirban Adhikary <anirban.adhikary@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: shell script doesnot executing Message-ID: <1134720654.34653.37.camel@devilBSD.freeBSD> In-Reply-To: <71c73b070512152153h507fae3eo22e3b2d52df1202f@mail.gmail.com> References: <71c73b070512152153h507fae3eo22e3b2d52df1202f@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 > echo "Server is up and working" $host > else > echo"Server is not up and not working" $host > fi I reworked your script a bit, it is working for me maybe it will for you: #! /bin/sh echo -n "Enter the IP or Hostname of the Server: " read host ping -c2 $host > file2; if `test $? = 0`; then echo "Server is up and working" $host else echo "Server is not up and not working" $host fi TEST: hde{/usr/home/hde} $ ./test.sh Enter the IP or Hostname of the Server: 193.169.1.1 Server is up and working 193.169.1.1 hde{/usr/home/hde} $ ./test.sh Enter the IP or Hostname of the Server: 193.169.1.111 Server is not up and not working 193.169.1.111 hde{/usr/home/hde} $ cat file2 PING 193.169.1.111 (193.169.1.111): 56 data bytes --- 193.169.1.111 ping statistics --- 2 packets transmitted, 0 packets received, 100% packet loss hde{/usr/home/hde} $ -- 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------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1134720654.34653.37.camel>