Sponsored Content
Full Discussion: Script to Ping Servers
Top Forums Shell Programming and Scripting Script to Ping Servers Post 302855313 by gkelly1117 on Thursday 19th of September 2013 02:51:02 PM
Old 09-19-2013
Script to Ping Servers

Hey, It's me again! Still trying to learn to become a better scripter on the job Smilie

New challenge for assistance, if anyone cares to help, and its two parted! First part, I wanted to create a script at work that would ping a server that was supplied in an argument, then a count (amount of times) it should be pinged.

I came up with a solution that I thought worked.

Code:
#!/bin/bash
#Written by: Manny
#Date: 9/19/2013


HOST=$1
COUNT=$2

for hosts in $HOST
do
  ping=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq #IwantToCheckAgainstHalfofCOUNT ]; 
then 
        echo "Host : $hosts is down"
        return 1
  fi
    else return 0
done

I was pretty much told, "No, I want it done a different way" (There is a method to their madness I suppose)

Any-ways, I have some pseudo code of how I interpret how they want it, but cant figure out how to get both Counters to work.

Code:
while COUNT <= number_of_times_i_ask_it_to_ping
    if ping -c1 host_i_ask_it_to_ping
        PINGCOUNT++
    fi
    COUNT++
done

So Any Help Making that into something i can use would be greatly appreciated it.

also. if you see my first solution. I have a threshold of 50% of packets lost that i wanted to test that if statement against, but couldn’t think of a way to do that either. so for my own PERSONAL reasons, if anyone can think of a cool way to go about doing that, would be greatly appreciated as well.



Quick Edit: in my pseudo code, i use a while loop, but it doesn't have to be. I'm sitting here playing with for loops like
Code:
for (( count=1; count <= $COUNT; count++ )) 
do 
ping -c 1  $HOST
done

to see if i can make that work instead.

Last edited by gkelly1117; 09-19-2013 at 04:03 PM.. Reason: Adding to explanation
 

10 More Discussions You Might Find Interesting

1. AIX

Script to ping servers in a file

I would like to ping a list of servers in a text file. Can anyone help? (1 Reply)
Discussion started by: gbarkhor
1 Replies

2. UNIX for Advanced & Expert Users

script to ping servers

Hi , I would like to automate a script to ping all the unix servers perodically thru cronjob. Is there any script out there? If so Please give me. Thanks in advance. (2 Replies)
Discussion started by: sriny
2 Replies

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

4. Shell Programming and Scripting

Ping the hostname of many servers using a script

Hi We have some 300 servers in the Data center and some of them are running with AIX and some of them are running with Solaris. I need a script which can be run in one of the server and that script should ping the hostname of all the 300 servers. Also the script should notify if any server is... (9 Replies)
Discussion started by: newtoaixos
9 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

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

7. Shell Programming and Scripting

Ping script to list of servers

Hi Friends, I have experience in redhat/ Ubuntu OS, but I am very new to solaries os. my servers OS is Oracle Solaris 10 8/11 s10x_u10wos_17b X86. I have a file contains 200 servers IPs one by one. now I want a script to chaeck which IPs are pinging, not pingning. I... (8 Replies)
Discussion started by: kumar85shiv
8 Replies

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

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

10. 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
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 03:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy