There isn't actual word "ECHO_REPLY" but a line that starts with "64 bytes from [...]" when the script reaches the target computer (eg. google.com). Now, how do you write an if statement like:
PHP Code:
if (line starts with "64 bytes from [...]") do break; fi
Quote:
Originally Posted by scottn
But I'm not really understanding why you have a for-loop in the first place to ping the same thing 30 times...
You're right, I should use while or until, but I don't know how to express the terminating if statement.
But I'm not pinging "the same thing", because I increase TTL in each iteration and get new servers where the packet "expires".
This is (almost) it:
PHP Code:
#!/bin/bash domain=${1-www.google.com}; #If no argument, then do www.google.com.
for ((i=1; i<=30; i++)) do ping -c 1 -t $i $domain | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' done
exit 0;
Above script outputs this:
EDIT: Wait, I'm doing it wrong: I also pickup google's IP from each line "PING www.l.google.com (209.85.135.103) 56(84) bytes of data.". How do I exclude these IPs with grep?
Last edited by courteous; 12-05-2010 at 04:01 PM..
Reason: found error(s)
i need to write a script that can loop through ej.192.162.0.0 to 192.162.0.256
find the ones that are connected and the ones not connected
write the name , ip address and connection status of each one in a file
to later use it in perl to create a web page with the information
thanks guys (1 Reply)
need to check on some hosts and send an email if there status changes
I wanna put together a script in bash that will allow me to check the up/down state of a single host via ping
i want it to run in a continuous loop so I can just fire the script and forget about it(dont want cron to drive... (2 Replies)
Hi Gurus
I have a file called /tmp/CMDB which looks like this
serial: 0623AN1208
hostname: server1
model: x4100
assetID: 1234
I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Hi,
I am using su within a for loop. As you might expect, it prompts for password during each loop execution. Here is my piece of code:
for i in $LIST
do
if
then
DATABASE=`echo $i | awk -F "|" '{ print $1 }'`
USER_ID=`echo $i | awk -F "|" '{ print $2 }'`
su - apstage -c... (1 Reply)
Hi all
Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Hi All
i have an issue with ping, we are using dhcp and so if the machine has been offline and i ping it, i get " ping: unknown host <hostname>
is there a way i can stick a loop somewhere so it would keep trying when it got the unknown host error and then when the machine came back online... (2 Replies)
Hi All,
Below is the very simple code snippet but it si giving me syntax error
#!/bin/bash
#To ensure If JMS directory exists or not
ServerName=$(hostname)
#To ensure If JMS directory exists or not
echo $ServerName
if ;
then
echo "Inside First If"
if ;
then
echo 'JMS... (4 Replies)
I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off....
I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Running 3650 switch. I have this odd issue where I cannot get 4 new Centos 7 boxes pinging out on public IPs (nor pinging in), only gateway .1 and first public IP .2
This is what I see, which doesn't look normal. How do I fix this?
The server itself is configured fine (Centos 7)
# cat... (0 Replies)