BlkSwrd wrote:...so in there is a "0%" set of characters which is what states that everything is OK... right?
Not exactly. If you run just the shell script line in the Apple Script Editor (and open the Events & Results panes) you will get:
- Code: Select all
tell current application
do shell script "/sbin/ping -c10 75.26.175.254|grep -c time=" as string
--> "10"
end tell
Result:
"10"
But, your AppleScript is looking for 0% and you will never find it. This is because in the d
o shell script command, the output of the
ping command is sent as input (the "
|" symbol) to the
grep command.
grep then counts (the -c argument) the number of lines containing the string "time=" (which indicates a successful ping response). Then
grep returns the count to your AppleScript.
The reason for this is that even if you get only 1 packet out of 10 through to your ISP, it is highly probable that the equipment at your end is running properly, and no reset is required. So, you need to test the result to see if the response is greater than zero. Something like this:
- Code: Select all
tell application "IndigoServer"
try
set this_result to do shell script ("/sbin/ping -c10 75.26.175.254|grep -c time=")
if this_result = 0 as integer then
execute group "Reset Internet / Network Router"
log "No ping response received (0 of 10)"
end if
on error error_message
execute group "Reset Internet / Network Router"
log "Command failure testing network connection: " & error_message
end try
end tell
will do what you want.
However, you can simplify this to:
- Code: Select all
tell application "IndigoServer"
try
set this_result to do shell script ("/sbin/ping -c10 75.26.175.254|grep -c time=")
on error error_message
execute group "Reset Internet / Network Router"
log "Command failure testing network connection: " & error_message
end try
end tell
since the shell script will return an error if there are no responses received. So, there is really no need to actually look at the count.
Finally, if you are running this as an embedded script, you can trim it down fi=urther to just:
- Code: Select all
try
set this_result to do shell script ("/sbin/ping -c10 75.26.175.254|grep -c time=")
on error error_message
execute group "Reset Internet / Network Router"
log "Command failure testing network connection: " & error_message
end try
since the tell block isn't necessary inside Indigo.
You can test your script by changing the IP Address you ping to: 75.26.175.25
3 since that address does not exist and no responses will be received.