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
PCT-SCANNER-SCRIPT(1)					      General Commands Manual					     PCT-SCANNER-SCRIPT(1)

NAME
pct-scanner-script - easy scan and create merged DjVu and PDF documents for archiving SYNOPSIS
pct-scanner-script [--help] DESCRIPTION
pct-scanner-script is a bash script and configuration system to easily scan documents and create a digital archiving. It can create DjVu PDF and JPEG outputs, in merged and individual files. It also has a configuration system where different configurations can be defined, making it easy to switch between configurations. Please use pct-scanner-script --help to find all program options, the complete help, and all examples. Features: - auto archiving in merged and individual DjVu, PDF, and JPEG files - auto and manual resume when scanning somehow fails - cascading configuration system, for easy customizing - easy command-line-style bash program, with useful options - archiving made possible with both adf and flatbed scanners - built for productivity and daily use - uses bash, scanadf and other mainstream processing tools - multilanguage commandline output OPTIONS
-h, --help, -? Show summary of options, help, and examples. DEBUGGING
This program is a helper script to easy scan and automated digital document archiving for normal and adf scanners. You can debug this script by running it as bash -x pct-scanner-script [options]. The script is just a nice wrapper for the scanadf, DjVu and PDF tools. SEE ALSO
scanadf(1), AUTHOR
pct-scanner-script and this manual page are written by: Jelle de Jong <jelledejong@powercraft.nl>. March 31, 2009 PCT-SCANNER-SCRIPT(1)
All times are GMT -4. The time now is 07:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy