Monitoring host with ping

Monitoring host with ping

Post by Floyd Davidso » Sun, 31 Dec 1899 09:00:00




>I was trying a sample shell script named Wping.sh to monitor an
>experimental virtual domain Web server to ping every 10 minutes, if no
>data packets received back from remote host it sends me e-mail like:

>#!/bin/bash
>while [ 1 ]
>do
>   PING=`ping -c 3 -s 56 mywebserver | grep recieived | awk -F,
>   '{print $2 }' | awk '{print $1}'`

Assuming the above two lines were actually all on one line, this
works.  However...

Why use the "-s 56" option with ping?  That is the default behavior.

And why poke the results through awk at all, much less twice???
All you really need to know is if ping succeeded even one time,
and if it did there will be a line returned that looks something
like this:

  64 bytes from 192.168.0.30: icmp_seq=0 ttl=255 time=0.1 ms

So..., grep for something unique in that line...

  ping -c 3 mywebserver | grep "64 bytes"

The status of that command is then returned in $?, which you
can either save or you can use directly with a script something
like this

  #!/bin/bash
  remote=mywebserver
  if ping -c 1 $remote | grep -q "64 bytes";then
    echo $remote online
  else
    echo $remote offline
  fi

>   if [ $PING -eq 0 ]; then
>       echo "Your server is off network" | mail -s "PING FAILED"


The two lines above must be one line also.

Quote:>   fi
> sleep 600
> done

>Somehow it kept getting error:
>./Wping.bash: [: -eq: unary opeator expected

>So I then tried:

>if [ "$PING" - eq "0" ]; then echo ...

>it sez:

>./Wping.sh: [: : integer expression expected

>Anyone can help for correct syntaxing to work with Linux?  Thanks.

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

Monitoring host with ping

Post by Jimmy Navarr » Sun, 31 Dec 1899 09:00:00


I was trying a sample shell script named Wping.sh to monitor an
experimental virtual domain Web server to ping every 10 minutes, if no
data packets received back from remote host it sends me e-mail like:

#!/bin/bash
while [ 1 ]
do
   PING=`ping -c 3 -s 56 mywebserver | grep recieived | awk -F,
   '{print $2 }' | awk '{print $1}'`
   if [ $PING -eq 0 ]; then
       echo "Your server is off network" | mail -s "PING FAILED"

   fi
 sleep 600
 done

Somehow it kept getting error:
./Wping.bash: [: -eq: unary opeator expected

So I then tried:

if [ "$PING" - eq "0" ]; then echo ...

it sez:

./Wping.sh: [: : integer expression expected

Anyone can help for correct syntaxing to work with Linux?  Thanks.

 
 
 

1. Monitoring host with ping

I was trying a sample shell script named Wping.sh to monitor an
experimental virtual domain Web server to ping every 10 minutes, if no
data packets received back from remote host it sends me e-mail like:

#!/bin/bash
while [ 1 ]
do
   PING=`ping -c 3 -s 56 mywebserver | grep recieived | awk -F,
   '{print $2 }' | awk '{print $1}'`
   if [ $PING -eq 0 ]; then
       echo "Your server is off network" | mail -s "PING FAILED"

   fi
 sleep 600
 done

Somehow it kept getting error:
./Wping.bash: [: -eq: unary opeator expected

So I then tried:

if [ "$PING" - eq "0" ]; then echo ...

it sez:

./Wping.sh: [: : integer expression expected

Anyone can help for correct syntaxing to work with Linux?  Thanks.

2. remote logging with ssh.

3. Strange network problems - pings to host are fine, pings from host fail

4. newbie question: applying .diff

5. Can't ping the host name or host IP address from host.

6. Netscape - loging ip not name

7. can't ping host or host IP from host ?

8. Getting user access on /dev/mem

9. ping <ipv6-host> does not work, ping <ipv6-ip> does

10. Can't ping local host but can ping others

11. could ping by numeric ip,BUT cant ping by hosts name

12. Get 'cannot connect to host', yet can ping remote host!!

13. nslookup works, ping <host> replies unknown host