Ping Command Not Outputting to Text file

Hi all,

I’ve posted on here b4 and I must start by saying a big thanks to all those that have helped!

I am developing a network diagnostic tool using automator and applescript for Students living in Halls of Residence.

One of the features of the tool is that it pings the local host then the default gateway and finally an external website. It then pipes the results to a text file. I have specified that 4 ping requests will be sent at each stage. Below is a sample command (I’m not on my Mac so had to remember the code…)

Do shell script "ping -c4 www.google.com >> Output.txt " with administrator privileges

When the Network is operational then the ping command behaves exactly as you would expect and records the data to the text file without issue.

However, If I unplug my ethernet connection or disable my adaptor Ping does not write to the file and instead hangs and thus the file is not created. In Windows if the machine can not ping the destiantion it simply records the failed results. However, in OSX, particularly when outputting to a file, Ping just seems to hang when it can not find the specified host.

Is there anything I can add to the ping command to force it to exist if it does not find a host? Or is there any other way round this. If not, I won’t be able to include it in my program which will be a significant blow to the results i’m hoping to reach! Any advise would be welcome?!

-Max

Unplug your network and try this command directly in the Terminal.

ping -c4 [url=http://www.google.com]www.google.com[/url] >> Output.txt

You will see that it errors and the error output text is shown in the Terminal window. So ping doesn’t hang, it just outputs the error text to a different place than the text of a successful try.

So to fix your problem you just need to tell ping to also output the error text to the same place as the success text. This will do that…

ping -c4 [url=http://www.google.com]www.google.com[/url] >> Output.txt 2>&1

Thanks,

This sounds very promising to me! I will follow the instructions tomorrow and let you know the results!

Thanks again for helping here.

-Max