Ping not found from the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ping not found from the script
# 1  
Old 10-12-2009
Ping not found from the script

Hi,

I have written a script which pings a host. When I executed the script, it is saying that test_mail.sh: line 1: PING: command not found
But if I run the ping from command prompt like "ping -c 1 piias1576" I am getting perfect result.

Code:
`/bin/ping -c 1 piias1576`
if [ $? != 0 ]
then
mail sibasha -s"piias1576 is down" -c rautsha; pendemna < piias1576_msg_fail
else
mail sibasha -s"piias1576 is up" -c rautsha; pendemna < piias1576_msg_success
fi

Can anyone tell me where I am doing the wrong?
# 2  
Old 10-12-2009
are you sure /bin/ping exists?
# 3  
Old 10-12-2009
Quote:
Originally Posted by siba.s.nayak
if I run the ping from command prompt
What does which ping return?
# 4  
Old 10-12-2009
Not every UNIX has ping in /bin/. Run
Code:
which ping
type ping

and use that path.
# 5  
Old 10-12-2009
Actually First I wrote this line (`/bin/ping -c 1 piias1576`) as (`ping -c 1 piias1576`) and found the PING not found, So I checked the which ping and changed with full path.
# 6  
Old 10-12-2009
ping script on Solaris 8

I don't know exactly what your OS is, but I tried the following script below on a Solaris 8 system. To ensure it would work, I had to a) add as the first line #!/bin/sh (because I run c-shell on that machine) and b) remove the beginning and ending `. Also added targetHost var, just for niceness.

#!/bin/sh

targetHost="yourhost"

/usr/sbin/ping -c 1 $targetHost

if [ $? != 0 ]
then
echo "$targetHost is down"
else
echo "$targetHost is up"
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Shell Programming and Scripting

Script with ping

I have a question is there any posibility for writing a script that you can see if a pc in your network is up of down , when you run this script for ex. ./test.sh 63 45 54 , which are the ip adresses of the computers , when you give the last digit of the ip adres as argument 63 , 45 and 54 are... (5 Replies)
Discussion started by: Roggy
5 Replies

3. Shell Programming and Scripting

ping script

hello fellows, I need help with a script, I'm using this one HOSTS="192.168.10.9 192.168.10.15 " SUBJECT="Attention - Gateway San Martin DOWN " COUNT=1 EMAILID="lmail@mydomain.com" for myHost in $HOSTS do count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2... (2 Replies)
Discussion started by: lucas.fradusco
2 Replies

4. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

5. Shell Programming and Scripting

Using ping in script

Hi. I have a server with multiple network ports that need to be tested to a list of destinations. I'm trying to write a scripts to automate this but can't seem to get past an error and could use some help. I have two test files one contains the ip addresses of the onboard NICs and the other... (10 Replies)
Discussion started by: mikez104
10 Replies

6. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

7. Shell Programming and Scripting

Help With Ping Script

Hello all...I'm new to Unix and learning. What I'm trying to create is a script that will ping a known range of IP addresses, say 192.168.1.1 to 192.168.1.254. For each address that no reply is received, that address will be written to a log file that will be emailed to an administrator. My wife... (1 Reply)
Discussion started by: spmitchell
1 Replies

8. Programming

python little ping script

Hi everyone, I'm a newby in the python languages, and I try to make some parallels to shell. My question is how ca I give the information to python that the line 3 "r=...." the string "line" is a variable. import os, re line = "localhost" r = "".join(os.popen("ping line -c... (2 Replies)
Discussion started by: research3
2 Replies

9. Shell Programming and Scripting

Ping script

I want find from a file , where list of hosts is given . Whether SSH is running on that Hosts and and create 2 files : HOSt-SSH-Running HOST-SSH-Not-running In the list we have some Windows and Unix Servers, windows servers do not have sshd running. (2 Replies)
Discussion started by: sriram003
2 Replies

10. Shell Programming and Scripting

Ping Script

hello, I am looking to make a script that will ping a remote ip address. Upon completion of the ping I want the program to either ping again if the # of packets transmitted is equal to the number of packets received or exit if the two values are unequal and information was lost. I am not sure if I... (3 Replies)
Discussion started by: mcrosby
3 Replies
Login or Register to Ask a Question