Hey, It's me again! Still trying to learn to become a better scripter on the job
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.
#!/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.
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
for (( count=1; count <= $COUNT; count++ ))
do
ping -c 1 $HOST
done
to see if i can make that work instead.