Scripting the parallel execution of a tedious task
December 12, 2006 12:03 PM
Subscribe
Calling all shell script gurus! Help me write a command that performs an action on items in a list in parallel (as opposed to sequentially).
I am trying to write a command that zeroes out the data on any number of attached disks simultanously (or nearly so). I started with the basics and have written the script below that accomplishes the task sequentially. (This is in Mac OS X, bash shell):
diskutil list | grep /disk | grep -v disk0 | sed 's|/dev/||g' | \
while read DISK; do
diskutil zeroDisk $DISK
done
The first line returns a list of attached disks:
disk1
disk2
disk3
etc... all except disk0.
Nothing I care about resides on any disk but disk0, which is why it's excluded. The while loop executes the 'diskutil zerodisk' command on each item in the list. I can manually start this command on each disk and the computer will happily perform the tasks in parallel. How can I script the parallel execution of this task?
posted by pmbuko to computers & internet (7 comments total)
1 user marked this as a favorite
"bg diskutil zeroDisk $DISK"
or
"diskutil zeroDisk $DISK &"
posted by Good Brain at 12:09 PM on December 12, 2006