- Notifications
You must be signed in to change notification settings - Fork13
Easy parallel execution of commands with live feedback
License
fd0/machma
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
In order to fully utilize modern machines, jobs need to be run in parallel. Forexample, resizing images sequentially takes a lot of time, whereas working onmultiple images in parallel makes much better use of a multi-core CPU andtherefore is much faster. This tool makes it very easy to execute tasks inparallel and provides live feedback. In case of errors or lines printed by theprogram, the messages are tagged with the job name.
machma by default reads newline-separated values and replaces allcommand-line arguments set to{} with the file name. The number of jobs isset to the number of cores for the CPU of the hostmachma is running on.
Resize all images found in the current directory and sub-directories to1200x1200 pixel at most:
$ find. -iname'*.jpg'| machma -- mogrify -resize 1200x1200 -filter Lanczos {}
The command specified after the double dash (--) is executed with eachparameter that is set to{} replaced with the file name. At the bottom, a fewstatus lines are printed after a summary line. The lines below visualize thestatus of the instances of the program running in parallel. The line for aninstance will either contain the name of the file (in this case) that is beingprocessed followed by the newest message printed by the program.
Ping a large number of hosts, but only run two jobs in parallel:
$ cat /tmp/ips| machma -p 2 -- ping -c 2 -q {}The programping will exit with an error code when the host is not reachable,andmachma prints an error message for all jobs which returned an error code.
A slightly more sophisticated (concerning shell magic) example is thefollowing, which does the same but recduces the output printed byping a lot:
$ cat /tmp/ips| machma -- sh -c'ping -c 2 -q $0 > /dev/null && echo alive' {}
Using--timeout you can limit the time mogrify is allowed to run per picture. (Prevent jobs from 'locking up')The value for timeout is formatted in golangtime.Duration format.When the timeout is reached the program gets canceled.
$ find. -iname'*.jpg'| machma --timeout 5s -- mogrify -resize 1200x1200 -filter Lanczos {}
Sometimes filenames have spaces, which may be problematic with shell commands.Most of the time, this should not be a problem at all, sincemachma runsprograms directly (using theexecve syscall on Linux for example) instead ofusingsystem(). For all other cases there's the--null (short:-0) optionwhich instructsmachma to read items separated by null bytes from stdin. Thiscan be used with the option-print0 of thefind command like this:
$ find. -iname'*.jpg' -print0| machma --null -- mogrify -resize 1200x1200 -filter Lanczos {}
Installation is very easy, install a recent version of Go and run:
$ go run build.go
Afterwards you can view the online help:
$ ./machma --helpUsage of ./machma: --no-id hide the job idin the log --no-name hide the job namein the log --no-timestamp hide thetime stampin the log -0, --null use null bytes as input separator -p, --procs int number of parallel programs (default 2) --replace string replace this stringin thecommand to run (default"{}") --timeout durationset maximum runtime per queued job (0s == no limit)
About
Easy parallel execution of commands with live feedback
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.


