• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Ignoring responses from "do shell script"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ignoring responses from "do shell script"


  • Subject: Re: Ignoring responses from "do shell script"
  • From: Graff <email@hidden>
  • Date: Thu, 11 Mar 2004 01:45:50 -0500

On Mar 10, 2004, at 6:34 PM, Martin Orpen wrote:

on 10/3/04 11:03 pm, Emmanuel at email@hidden wrote:

At 10:25 PM +0000 10/03/04, Martin Orpen wrote:

set ipBlock to {}
repeat with i from x to y
set theIP to IPbase & "." & i
set ipBlock to ipBlock & theIP
end repeat

This works fine when x and y generate up to 82 items. Go over that number
and script fails.

I'm not sure if you mean, the AppleScript fails or the ping. Anyway I think
others have made clear that it's always better to write "set end of ipBlock to
theIP" than "set ... to ... & ..."

I'm not sure what the problem is specifically. The script is running inside
a try block inside an Xcode project.

If I remove the "try" I get an error of:

sh: fork: Resource temporarily unavailable (128)

The list of IPs are being fed into Gnarlie's shell script here:

repeat with theIP in ipBlock
do shell script "ping -c 1 " & theIP & " >> " & pingPosix & "
2>&1 &"
end repeat


Is there a limit to the number of shell processes I wonder?

Most likely, yes. I mentioned this a bit further up in the message thread along with a solution (which I found a bug in and fixed below). Basically it looks like there is a hard limit of the number of processes each user can have going at once under Darwin (the Unix base for Mac OS X). This limit appears to be 100, you can read a little about it here:
<http://www.opendarwin.org/pipermail/hackers/2003-April/001653.html>

And from the appropriate header file (/Developer/SDKs/MacOSX10.3.0.sdk/usr/include/sys/syslimits.h):

#define CHILD_MAX 100 /* max simultaneous processes */

The workaround is to do the pings in batches, I would say 50 at a time is safe. Do 50, wait 15 seconds, do 50 more, etc. That way each batch has a chance to finish and clear out before the next batch starts. It will take 15 seconds per 50 pings but that's much better than 15 seconds for each ping!

Here's the reworked example script which uses this method:
-------------
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

set batchSize to 50
set theCount to count of pingList
repeat with i from 1 to theCount by batchSize
repeat with j from 0 to (batchSize - 1)
if (i + j) <= theCount then
set theIP to item (i + j) of pingList
do shell script "ping -c 1 " & theIP & " >> " & pingPosix & " 2>&1 &"
else
exit repeat
end if
end repeat
delay 15
end repeat

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
-------------


-Ken
_______________________________________________
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.


  • Follow-Ups:
    • Re: Ignoring responses from "do shell script"
      • From: Christopher Nebel <email@hidden>
References: 
 >Re: Ignoring responses from "do shell script" (From: Martin Orpen <email@hidden>)

  • Prev by Date: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)
  • Next by Date: Re: do visual basic
  • Previous by thread: Re: Ignoring responses from "do shell script"
  • Next by thread: Re: Ignoring responses from "do shell script"
  • Index(es):
    • Date
    • Thread