shell script for ping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script for ping
# 8  
Old 05-10-2010
This is what i got for you in my archive which i used it in AIX quite long time ago, i hope it helps you...

Code:
# cat host
150.150.102.10
150.150.105.10
150.150.106.10
150.150.150.150
# cat pn
while read hostname
do
PL=$(ping -c 10 $hostname | grep "% packet" | awk '{gsub("%","",$0);print $7}')
 if [[ $PL -gt 50 ]]
  then
  echo "$hostname is not pinging" >> status
  else
   echo "$hostname is pinging" >> status
  fi
done < host
# cat status
150.150.102.10 is pinging
150.150.105.10 is not pinging
150.150.106.10 is pinging
150.150.150.150 is not pinging
#

# 9  
Old 05-10-2010
on Solaris, I found this,

Code:
bash-3.00$ uname -a
SunOS your_host 5.10 Generic_127111-11 sun4u sparc SUNW,Sun-Fire-V440
bash-3.00$ /usr/sbin/ping your_host
your_host is alive
bash-3.00$ echo $?
0
bash-3.00$ /usr/sbin/ping invalid_host
/usr/sbin/ping: unknown host invalid
bash-3.00$ echo $?
1
bash-3.00$

you can have something like this:
Code:
/usr/sbin/ping your_host >/dev/null 2>&1
status=$?
if [ "$status" -eq "0" ]; then
 echo "ping success"
else
 echo "ping failed"
fi


Last edited by clx; 05-10-2010 at 10:19 AM.. Reason: changed "$status to "$status"
# 10  
Old 05-10-2010
Are you planning to create something that will check the state of the servers?
I mean if it is pingable is up if not is down?
# 11  
Old 05-10-2010
Script for ping?

Ping varies over platforms and versions, but it tends to return a code that is reliable to consistent so that 'if ping ${target}' works.


You do need to be more clear and complete with such questions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to ping multiple servers

Hi I did the following script to ping multiple servers, but I keep on receiveing duplicate emails for one server that is down: #!/bin/bash date cat /var/tmp/servers.list | while read output do ping -c 1 "$output" > /dev/null if ; then echo "node $output is up" else ... (10 Replies)
Discussion started by: fretagi
10 Replies

2. 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

3. Shell Programming and Scripting

Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team, Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail. Need this script to check reachability of multiple nodes at same time. Help me. I use this but not working... Eg. in this script i need to telnet... (4 Replies)
Discussion started by: Ganesh Mankar
4 Replies

4. Shell Programming and Scripting

Ping shell script - need urgent help

Hi friends, i have a file contains IP address like below cat file.txt 10.223.20.1 10.223.20.2 10.223.20.3 10.223.20.4 10.223.10.5 . . . like this Now i want to make a script which gives output whether each ip is pinging or not... the result will be like this 10.223.20.1 up... (9 Replies)
Discussion started by: siva kumar
9 Replies

5. 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

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

Unix Shell Script to ping systems & make a log

Hi, I need to ping all the systems in my network and then create a log for the ones, from where I successfully get the ping-response (ICMP packet). Now, I've used the ping command successfully, but am unable to use 'grep' command to locate the IPs for which the ping was successful (so that I... (5 Replies)
Discussion started by: psychoTHEIST
5 Replies

8. Shell Programming and Scripting

Shell Script for ping, Linux

I woul like to create a script in order to make a ping to a server and save in a variable a 1 if respond or a 0 if it doesnt. Then with that I could make a graffic of the server, for how long it is up.:b: So far I have this: if ; then #if the ip respond the ping shows online echo... (3 Replies)
Discussion started by: jsebastiang0
3 Replies

9. Shell Programming and Scripting

Shell script to ping a range of IPs

Hi Can someone give me a shell script that can ping a range of IPs and return IPs which are not pingable. Range for example say 192.168.0.1 to 192.168.0.50 and whichever are not pingable then return the IP. Thanks for your help (3 Replies)
Discussion started by: tannu
3 Replies

10. Shell Programming and Scripting

shell script queries: $home; broadcast ping

Dear all, This is the Bionic Fysh again. I have two quick questions: 1- when writing shell scripts, how does one allow the tilda ~ into the script ? e.g ls ~; ls ~me; user=you; ls ~$user (N.B I think that for this one you need: ls `~$user`) 2- In FreeBSD 4.0, I would like for a... (6 Replies)
Discussion started by: bionicfysh
6 Replies
Login or Register to Ask a Question