Bash loop ping successful

I'm thinking that this needs to be changed to a while clause, at the moment it'll wait till all 10000 pings are done, I need it to return when the ping is successful. The program "say" is on OSX it makes the computer speak.

echo begin ping
if ping -c 100000 | grep timeout;
then echo `say timeout`;
else echo `say the internet is back up`;

OK I don't have rights to answer my own question so here's my answer for it after playing around:

Thanks, yeah I didn't know about $? until now. Anyway now I've gone and made this. I like that yours doesn't go forever but in my situation I didn't need it to stop until it's finished.

echo "begin ping"
while [ $intertube -ne 1 ]; do
        ping -c 3
        if [ $? -eq  0 ]; then
                echo "ping success";
                say success
                echo "fail ping"
echo "fin script"


You probably shouldn't rely on textual output of a command to decide this, especially when the ping command gives you a perfectly good return value:

The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value from <sysexits.h> if an error occurred.

In other words, use something like:

((count = 100))                            # Maximum number to try.
while [[ $count -ne 0 ]] ; do
    ping -c 1                      # Try once.
    if [[ $rc -eq 0 ]] ; then
        ((count = 1))                      # If okay, flag to exit loop.
    ((count = count - 1))                  # So we don't go forever.

if [[ $rc -eq 0 ]] ; then                  # Make final determination.
    echo `say The internet is back up.`
    echo `say Timeout.`

Need Your Help

using ConcurrentStack

c# multithreading stack

I need to use the stack data structure to save strings. But this stack will be accessed from multiple threads. So my question is, how do I use the ConcurrentStack to add data from multiple threads?

inserting a , in a number thats greater than 999


im working on a project that is calculating the total population for given countries and its in the hundreds of thousands. And i need to output the population with the ,'s in the appropriate place...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.