Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/machmaPublic

Easy parallel execution of commands with live feedback

License

NotificationsYou must be signed in to change notification settings

fd0/machma

Repository files navigation

Status badge for tests

machma - Easy parallel execution of commands with live feedback

Introduction

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.

Sample Usage

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.

demo: resizing files

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.

demo: ping hosts

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' {}

demo: ping hosts again

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

Files With Spaces

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

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2026 Movatter.jp