[wplug-bsd] test if a host is alive

Tom Rhodes trhodes at FreeBSD.org
Sat Sep 25 14:30:17 EDT 2004

On Fri, 24 Sep 2004 22:17:33 -0400 (EDT)
Brandon Kuczenski <brandon at 301south.net> wrote:

> I am writing an automated script to periodically copy files from my
> windows machine to my server for backup purposes.  I want the script to
> test to see whether the machine is awake before proceeding with the
> script [ I don't leave the windows machine running all the time ] .  Can
> anyone recommend a way to do that?  My first thought is ping, but I would
> like a command that just returns "true" if contact was successful after a
> fixed period of time and "false" if not -- maybe ping can do that, but I
> didn't see it in the options.

You can test if a command was successful with something like:

if [ $? != 0 ];
	then echo "bad";
	echo "good";

But set ping to only do a single request, peraps "ping -c 1 ADDR";
and this works fine in sh(1).

Tom Rhodes

More information about the wplug-bsd mailing list