Sunday 15 March 2015

bash - Limiting the number of subshells spawned -


I am trying to limit the limit of subsites which are generated in a script that I can use to my internal network To use sniffing, Linux works in our network to introspect the script to audit the server, but by the way I want to loop the loop ; For 255 produces all shells, therefore Because of this, more than 1000 processes have arisen, I need to be able to limit the amount of processes, and since the variable loses its value in a sub-shell, I can not understand one way to do this. Again, the script works, it only produces a tonne process - I need to maximize it, the maximum of 10 processes say:

  #! / Bin / bash for FILE = / root / ats_net_final network, in `$ Cat $ FILE` for $ IP, in the network. {1..255} Do (SYSNAME = `snmpwalk -v2c -c public -t1 -r1 $ ip sysName.0.2 & gt; / dev / null | awk '{Print $ NF}'` SYSTYPE = `snmpwalk -v2c - C public -t1 -r1 $ ip sysDescr.02> / dev / null | grep -o linux 'if [$? -q 0]; then "dollar per dollar" SYSNAME "exit 0; other echo" processed $ IP "Exhaust 0fi) and I did what works, but not in my case, because it does not matter, it will still create processes before logic to limit the processes. Code too long And I'm keeping things in the wrong area, or in the wrong order.  

Answers are accepted:

I have accepted the response from the hitcitizer in the answer. He could give me instructions on how logic works, allows me to work it Final script:

  #! / Bin / Bash FILE = / root / ats_net_final for network in `cat $ FILE`; $ IP in network For # {1..255}; For IP {1..255} (IP = $ network. $ Ip SYSNAME = `snmpwalk -v2c -c Public-T1-R1 $ IP sysName.02 & gt; / Dev / null | Awk '{print $ nf}' `SYSTYPE = 'snmpwalk -v2c -c public -t1 -r1 $ ip sysDescr.0 2 & gt; / Dev / null | Grep -o linux 'if [$? -q 0], then encode "$ SYSNAME" to 0; And "Processed $ IP" echo exit 0fi) and amp; If (($ ip% 10 == 0)); then wait; Fine Waiting    

An easy to limit the number of concurrent subshells to 10 The method is for:

  $ (seq 1 255) for IP; (<$ Ip instead & gt; with whatever $ you invest in that subsealand, with $ IP, $ Ip instead & gt;) & amp; If (($ ip% 10 == 0)); then wait; Waiting with the last wait   

The internal loop is not useful to go to the subclasses of the last round of overlap with those created in the first round of the next outer part.

No comments:

Post a Comment