[comp.protocols.tcp-ip] Testing if a host is up

car@trux.UUCP (Chris Rende) (02/16/91)

I have a shell script which does a FTP of a file over to another host.

I need a way to put a test ahead of the FTP that will determine whether
or not the other host is "up".

Here is what I have so far:

--------------------------------------------------------------------
# hostup - Written 01/30/91 by Chris Rende
# Last change: 01/30/91 by Chris Rende

x=`ping HOST 56 1 | fgrep packets | cut -c24`

if [ $x = 0 ]; then
	echo "HOST is down"
	exit 1
fi

echo "HOST is up"
exit 0
--------------------------------------------------------------------

Is there a better way? (I.e., more robust, less kludgy).
C program(s) welcome.

car.
-- 
Christopher A. Rende           Central Cartage (Nixdorf/Pyramid/SysVR2/BSD4.3)
uunet!edsews!rphroy!trux!car   Multics,DTSS,Unix,Shortwave,Scanners,UnixPC/3B1
trux!car@uunet.uu.net          Minix 1.2,PC/XT,Mac+,TRS-80 Model I,1802 ELF
trux!ramecs!car     "I don't ever remember forgetting anything." - Chris Rende

barmar@think.com (Barry Margolin) (02/16/91)

In article <529@trux.UUCP> car@trux.UUCP (Chris Rende) writes:
>I need a way to put a test ahead of the FTP that will determine whether
>or not the other host is "up".
>Here is what I have so far:

># hostup - Written 01/30/91 by Chris Rende
[Script omitted]

Except for the exact text of the message printed, the ping command does
exactly what your shell script does.  It returns 0 status if the host is
up, and non-zero when the host is down.

This is on SunOS 4.0.3.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

emv@ox.com (Ed Vielmetti) (02/16/91)

In article <529@trux.UUCP> car@trux.UUCP (Chris Rende) writes:

   I have a shell script which does a FTP of a file over to another host.

   I need a way to put a test ahead of the FTP that will determine whether
   or not the other host is "up".

Just an observation -- just because a host answers pings doesn't
necessarily mean it's up.  Consider that it might be in single user
mode doing backups, with the network interface up but no inetd
services running and the partition you want to FTP to unmounted.

Not to say that noticing that a few pings don't come back isn't a good
idea, but it's not sufficient to guarantee service availability.
Depending on your application, it might be enough.

--Ed

-- 
 Msen	Edward Vielmetti
/|---	moderator, comp.archives
	emv@msen.com

tkevans@fallst.UUCP (Tim Evans) (02/17/91)

In <EMV.91Feb16014229@poe.aa.ox.com> emv@ox.com (Ed Vielmetti) writes:

>In article <529@trux.UUCP> car@trux.UUCP (Chris Rende) writes:

>   I need a way to put a test ahead of the FTP that will determine whether
>   or not the other host is "up".

>Just an observation -- just because a host answers pings doesn't
>necessarily mean it's up.

Assuming you have appropriate /etc/hosts.equiv and/or .rhosts set up,
you could 'rsh' something like /bin/echo on the remote:

	if rsh remote [ -l user ] /bin/echo > /dev/null
	then whatever
	fi
-- 
UUCP:		{rutgers|ames|uunet}!mimsy!woodb!fallst!tkevans
INTERNET:	tkevans%fallst@wb3ffv.ampr.org
Tim Evans	2201 Brookhaven Ct, Fallston, MD 21047

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (02/18/91)

In article <1917@fallst.UUCP> tkevans@fallst.UUCP (Tim Evans) writes:
> Assuming you have appropriate /etc/hosts.equiv and/or .rhosts set up,
> you could 'rsh' something like /bin/echo on the remote:

That still wouldn't prove that ftp is available.

What's wrong with simply connecting to the service in question and
seeing whether it responds?

---Dan

ejm@riscit.NOC.Vitalink.COM (Erik J. Murrey) (02/20/91)

In article <1991Feb16.041439.1038@Think.COM>, barmar@think.com (Barry
Margolin) writes:
> In article <529@trux.UUCP> car@trux.UUCP (Chris Rende) writes:
> >I need a way to put a test ahead of the FTP that will determine whether
> >or not the other host is "up".
> >Here is what I have so far:
> 
> ># hostup - Written 01/30/91 by Chris Rende
> [Script omitted]
> 
> Except for the exact text of the message printed, the ping command does
> exactly what your shell script does.  It returns 0 status if the host is
> up, and non-zero when the host is down.
> 

Also, more as a heads up...  Some SLIP-ed or PPP-ed hosts have ICMP
messages filetered out specifically to prevent pings from clogging
low-speed links.  Although I don't necessarily agree with this, I do
see that the SLIP/PPP code allows this.

... Erik
---
Erik J. Murrey
Vitalink Communications NOC
ejm@NOC.Vitalink.COM	...!uunet!NOC.Vitalink.COM!ejm