help to ping a host, is it alive or not ...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help to ping a host, is it alive or not ...
# 8  
Old 01-27-2005
looks like that is working ok, the problem is here:

+ ping 148.202.1.29
148.202.1.29 is alive
+ 0=0
servscript: 0=0: not found
+ echo 148.202.1.29 esta muerto (<-- is dead, in spanish)
148.202.1.29 esta muerto

as you can see the ping works all right, and it does send a 0 as an indication that it all went fine and the host did respond, and echoes host is alive, but then it's that error that says: servscript: 0=0 not found... and it also echoes host is dead, even if it had already checked that it was alive...

im not sure what it is, i guess is some kind of syntax error but i dont know, it looks fine to me...
# 9  
Old 01-27-2005
Quote:
if ("$?"="0")

Try integer comparison ...

Code:
if  test $? -eq 0  then 
  echo " Alive"
fi

# 10  
Old 01-27-2005
Thanks, i already fixed it, seem that teh sintax was:

if ping $ipadr
then
echo "is alive"
else
echo "is dead"
fi

it seems thet the if statement just goes like if 0 do something... i didnt knew that... but thank you all for helping me Smilie

only one more thing: when it's pinging it shows the results, 148.202.15.70 is alive, and i dont want that to be shown, it only needs to run and do nothing if the host is alive, if a host doesnt answer send an email...

is it anyway to tell it that i dont need the output on the screen?
# 11  
Old 01-27-2005
Code:
echo "dead " > tmp

ping yahoo.com
if test $? -eq 0 
then
  sleep 0 ;
else
sendmail X@Y.com  < tmp
fi

# 12  
Old 01-27-2005
One more way .....

Code:
echo "dead " > tmp

ping yahoo.com
if test $? -eq 0
then
  stty -echo ;
  echo "Alive" ;
  stty echo ;
else
sendmail X@Y.com  < tmp
fi

# 13  
Old 01-28-2005
Bug Here's the script!

Thank you all for Helping me with my script, here it is finished, it's not fancy, it's actually very simple, but for monitoring less than 25 servers is ok.
I'll leave it Here if someone else wants to use it.

there are 2 files, servscript and strike1, servscript will be running in the background all day and pinging the hosts every 5 minutes, if the host is alive then it continues scanning a does nothing, if the host is dead it writes it's IP address to the file deadip, when it finish scanning all of the ip's in the ipaddresslist file, then it will start the striek1 script, whose only function is to wait a minute, just to make sure that the host didnt answered because it was busy, then it pings all of the ip's in the deadip file, if they are still dead it sends an email to the sytems administrator, strike1 finishes and control goes back to servscript where it sleeps for 5 minutes to start the scanning all over again...

$ cat servscript

#!/usr/bin/sh
#Sistema de Monitoreo de Servidores
#CENCAR

a=1
while (test "$a"!="0")
do
for ipaddress in `cat ipaddresslist`
do
if ping $ipaddress >> pingout
then
continue
else
echo $ipaddress >> deadip
fi
done
./strike1
sleep 300
rm deadip
rm pingout
done

$ cat strike1

sleep 60
for a in `cat deadip`
do
if ping $a >> pingout
then
continue
else
echo $a" No Respondio al Segundo Intento" | mailx -s "ADVERTENCIA DEL SISTEMA DE MONITOREO" xxxx@cencar.udg.mx
echo $a" No Respondio al Segundo Intento" | mailx -s "ADVERTENCIA DEL SISTEMA DE MONITOREO" xxxx@cencar.udg.mx
fi
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Ping to remote host failed

Actually. I was getting a ping to remote host failed for one of my etherchannel. When I checked it was in backup adapter and again I use to faileover and brought to primary channel. But it was again going to backup channel and giving me the alert ping to remotehost failed. When I checked the load... (3 Replies)
Discussion started by: Mohamed Thamim
3 Replies

2. Shell Programming and Scripting

Ping Response from the host name

Hi All, I have the requirement where am pinging the server and matching the IP address with the existing IP address. Below code is returning me the IP address and my requirement is i have to see that also whether it is pinging or not PING useipapd01 (172.22.32.87) 56(84) bytes of data. 64... (1 Reply)
Discussion started by: sharsour
1 Replies

3. Shell Programming and Scripting

Ping Host Until it is up and email

Hi I am trying to write a script which runs until the host is up. i got it figured out that it needs to be in loop till it return $? = 0. Not getting it through though. I am not sure about the 6th line !!! #!/bin/sh HOSTS="host.txt" ping(){ for myhost in "$HOSTS" do ping -c -1 "$myhost"... (8 Replies)
Discussion started by: Antergen
8 Replies

4. Solaris

able to ping all hosts but not able to traceroute any host

i am using solaris 10 and i am able to ping all the hosts but i am not able to traceroute any of them. how to fix this? (9 Replies)
Discussion started by: chidori
9 Replies

5. IP Networking

ping can not recognize host but host command can

Hi, I have a weird problem. when ever I do ping command like for example ping unix.comI get the following message: # ping unix.com ping: unknown host unix.com but when I use host the computer is able to know the host. # host unix.com unix.com has address 81.17.242.186 unix.com mail is... (2 Replies)
Discussion started by: programAngel
2 Replies

6. Solaris

Unable to ping Solaris VM from Xp host

Hi All, I am using Vmware Workstation 6.0.3 build-80004. Guest OS: Solaris 10 Host OS : Win XP I am getting request time out when i am trying to ping from XP ( cmd line) to Solaris VM - I have assigned IP 192.168.50.5 in Solaris VM ( Hostname: Tower1) and it is in UP status. ... (4 Replies)
Discussion started by: saurabh84g
4 Replies

7. Solaris

unable to ping a host in another domain

Hello I have a server in it.siroe.com I added it.siroe.com in /etc/resolv.conf. I still can't ping the server. any service to restart here? any other file to edit? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

8. Solaris

PING - Unknown host 127.0.0.1, Unknown host localhost - Solaris 10

Hello, I have a problem - I created a chrooted jail for one user. When I'm logged in as root, everything work fine, but when I'm logged in as a chrooted user - I have many problems: 1. When I execute the command ping, I get weird results: bash-3.00$ usr/sbin/ping localhost ... (4 Replies)
Discussion started by: Przemek
4 Replies

9. IP Networking

QNX host cannot ping SCO host, vice versa

The problem I am facing now is that the QNX host could not ping the SCO host and vice versa. They are in the same domain, ie, 172.20.3.xx. As I am very new to Unix, I guess I must have missed out some important steps. Pls help... Thanx alot (2 Replies)
Discussion started by: gavon
2 Replies

10. UNIX for Dummies Questions & Answers

Unable to ping host

Hi, dear all, I am rather new to Unix and have this problem where I cant seem to ping from 1 host to another. The scenerio is as follows: - 1 QNX host->Eth->1 SCO host the SCO host is configured with it's IP the QNX host is configured with another IP both in the same domain, ie, 172.20.3.XX... (3 Replies)
Discussion started by: gavon
3 Replies
Login or Register to Ask a Question