Re: Ignoring responses from "do shell script"
Re: Ignoring responses from "do shell script"
- Subject: Re: Ignoring responses from "do shell script"
- From: Graff <email@hidden>
- Date: Tue, 09 Mar 2004 15:40:12 -0500
I believe what you are running into is the normal timeout for a ping.
If you try the ping command in the terminal you will see that for an
"up" machine ping will return as quick as it gets its response. When
you ping a down machine it waits a suitable amount of time and then,
since ping got no response, reports it as down. Doing some testing,
that time appears to be about 10 seconds. I don't believe that time
can be adjusted.
However, if what you are doing is pinging a large number of hosts in a
serial fashion (which is what it appears like you are doing) why not
ping them in parallel instead?
------------
set pingList to {"192.168.0.10", "192.168.0.20", "127.0.0.1",
"192.168.0.40"}
set pingFile to ((path to desktop folder as text) & "pinglist.txt")
set pingPosix to quoted form of POSIX path of pingFile
tell application "Finder"
if exists file pingFile then delete file pingFile
end tell
repeat with theIP in pingList
do shell script "ping -c 1 " & theIP & " >> " & pingPosix & " 2>&1 &"
end repeat
delay 15
set theIPnums to do shell script "awk '/statistics/ { print $2 }' " &
pingPosix
set isUp to do shell script "awk '/received/ { print $4 }' " & pingPosix
set IPList to paragraphs of theIPnums
set upList to paragraphs of isUp
set theRecords to {}
repeat with i from 1 to count of IPList
copy {item i of IPList, (item i of upList) as integer} to end of
theRecords
end repeat
repeat with aRecord in theRecords
if item 2 of aRecord is greater than 0 then
display dialog item 1 of aRecord & " is up"
else
display dialog item 1 of aRecord & " is down"
end if
end repeat
------------
This way the most you will have to wait for any number of pings is 15
seconds plus whatever it takes to run through your list of addresses.
-Ken
On Mar 9, 2004, at 1:27 PM, Martin Orpen wrote:
I've got a script that sends a single ping to a number of IP addresses
and
then reports whether the machine is up or not.
Machines that are up respond very quickly, but those that are down
cause
delays of around 10 seconds per IP.
I've broken a few rules and managed to get the delay down to 5 seconds
by:
with timeout of 5 seconds
tell application "System Events"
set x to do shell script "ping -c 1 etc etc"
end tell
end timeout
But am not happy about using System Events to look after the process.
Does anybody know of another way to generate an error quicker with
shell
scripts so that I can get this time under 5 seconds?
(Although I can set the timeout to lower than 5 seconds I get incorrect
information coming back for anything less).
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.