Advertisement
trini

Untitled

Feb 23rd, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #!/bin/sh
  2. # Execute multiple processes in parallel
  3. # returns 1 if any process returns non-zero value
  4. # returns 0 otherwise
  5.  
  6. pids=''
  7. RET=0
  8. i=0
  9. OFS=$IFS
  10. IFS="~"
  11.  
  12. echo "0" > ./$$ # Delete previous content
  13. export retFile="$$"
  14.  
  15. # Start processes
  16. for w in $1
  17. do
  18. `eval "$w" > ./log$i.tmp; echo "$?" >> ./$retFile` &
  19. pids="$pids:$!"
  20. (( i+= 1 ))
  21. done
  22.  
  23. echo "Debug: pids=$pids"
  24.  
  25. IFS=':'
  26.  
  27. # Wait for all process to complete
  28. for p in $pids
  29. do
  30. if [ "x$p" != "x" ]
  31. then
  32. wait $p
  33. fi
  34. done
  35.  
  36. # Check return value
  37. while read line
  38. do
  39. if [ "$line" != "0" ]
  40. then
  41. RET=1
  42. break
  43. fi
  44. done < ./"$$"
  45.  
  46. # Cleanup
  47. IFS=$OFS
  48. rm ./$$
  49. exit $RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement