[NTLUG:Discuss] Script request

Fred James fredjame at fredjame.cnc.net
Mon Mar 2 18:00:25 CST 2009


Fred wrote:
> Has anyone got a script that cron could run to see if 
> a server is up and running? I just found out that a webserver
> over in the corner has been sitting there for 4 days waiting
> for someone to get the driver CD out of the drive and let
> it boot. This was after the power company ran down the 
> battery in the UPS unit. (well, not really, but you know...)
>
> I guess a simple ping test would work, since if it is up enough
> for the networking, then the rest is probably running, too.
> That would be better than now, which is nothing.
>
> Thanks,
> Fred
>   
Fred
Other responses offered may be your better choice - depending on need - 
but I offer this in case ...

First ... ping on my box yields something like this (first to 
demonstrate a failure, and second to demonstrate a success) ...
$ ping -c 3 fredless.net
ping: unknown host fredless.net
$ ping -c 3 www.cnc.net
PING www.cnc.net (207.155.248.100) 56(84) bytes of data.
64 bytes from tonnant.cnc.net (207.155.248.100): icmp_seq=1 ttl=240 
time=54.2 ms
64 bytes from tonnant.cnc.net (207.155.248.100): icmp_seq=2 ttl=240 
time=53.7 ms
64 bytes from tonnant.cnc.net (207.155.248.100): icmp_seq=3 ttl=240 
time=53.7 ms

--- www.cnc.net ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 53.714/53.891/54.223/0.234 ms
$

... so I could use something like ...

    ping -c 3 $Name | grep "packet loss" > Tempfile.txt
    x=`wc $Tempfile.txt | awk '{ print $1 }'`
    if test $x -eq 1
    then
       PkgSent=`cat $Tempfile | awk '{ print $1 }'`
       PkgRecv=`cat $Tempfile | awk '{ print $4 }'`
       PkgLoss=`cat $Tempfile | awk '{ print $6 }'`
    else
       PkgSent=0
       PkgRecv=0
       PkgLoss=0
    fi


Hope that helps
Regards
Fred James




More information about the Discuss mailing list