• Stars
    star
    487
  • Rank 90,352 (Top 2 %)
  • Language
    Go
  • License
    BSD 2-Clause "Sim...
  • Created over 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy parallel execution of commands with live feedback

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. For example, resizing images sequentially takes a lot of time, whereas working on multiple images in parallel makes much better use of a multi-core CPU and therefore is much faster. This tool makes it very easy to execute tasks in parallel and provides live feedback. In case of errors or lines printed by the program, the messages are tagged with the job name.

machma by default reads newline-separated values and replaces all command-line arguments set to {} with the file name. The number of jobs is set to the number of cores for the CPU of the host machma is running on.

Sample Usage

Resize all images found in the current directory and sub-directories to 1200x1200 pixel at most:

$ find . -iname '*.jpg' | machma --  mogrify -resize 1200x1200 -filter Lanczos {}

The command specified after the double dash (--) is executed with each parameter that is set to {} replaced with the file name. At the bottom, a few status lines are printed after a summary line. The lines below visualize the status of the instances of the program running in parallel. The line for an instance will either contain the name of the file (in this case) that is being processed 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 program ping will exit with an error code when the host is not reachable, and machma prints an error message for all jobs which returned an error code.

demo: ping hosts

A slightly more sophisticated (concerning shell magic) example is the following, which does the same but recduces the output printed by ping 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 golang time.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, since machma runs programs directly (using the execve syscall on Linux for example) instead of using system(). For all other cases there's the --null (short: -0) option which instructs machma to read items separated by null bytes from stdin. This can be used with the option -print0 of the find 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 --help
Usage of ./machma:
      --no-id              hide the job id in the log
      --no-name            hide the job name in the log
      --no-timestamp       hide the time stamp in the log
  -0, --null               use null bytes as input separator
  -p, --procs int          number of parallel programs (default 2)
      --replace string     replace this string in the command to run (default "{}")
      --timeout duration   set maximum runtime per queued job (0s == no limit)

More Repositories

1

grobi

Automatically configure monitors/outputs for Xorg via RANDR
Go
126
star
2

rabin-cdc

Fast implementation of Content Defined Chunking (CDC) based on a rolling Rabin Checksum in C.
C
46
star
3

fnordlicht

fnordlicht firmware in C, next generation
C
31
star
4

hackrf-one-pictures

Pictures of the final hardware version of hackrf
30
star
5

lbfs

Mirror of the original lbfs (Low Bandwidth File System) cvs repository at http://www.fs.net/cvs/lbfs/ (404)
C++
28
star
6

build-go

build.go - Program for building Go binaries without a GOPATH
Go
21
star
7

foodloader

Atmel ATmega serial bootloader
C
16
star
8

go-iptables

Bindings for some functions of libiptc
Go
11
star
9

split

Split large files into smaller ones using deterministic Content Defined Chunking
Go
10
star
10

jawbreaker-pictures

Pictures of the hackrf jawbreaker beta board
7
star
11

psha

Go
6
star
12

vmail

command-line for managing mailboxes and aliases for mail server setups based on the howto (English) (German) by Thomas Leister
Go
6
star
13

dab

Module-based dotfiles manager
Go
6
star
14

avrdude

git mirror (with own extensions) of the avrdude svn
C
4
star
15

talk-intro-go

Introduction to Go (in German)
Go
4
star
16

toothrotd

Daemon that listens for and logs rogue packets received (described via pcap filter expression)
C
4
star
17

serialclient

Program for debugging serial communication (eg with microcontrollers)
C
4
star
18

uens

Call scripts which run within the user's X session on ACPI or systemd events
Shell
4
star
19

randall

Go
3
star
20

ergodox-tmk

Firmware for the ErgoDox keyboard based on tmk
C
3
star
21

erpel

A better logcheck replacement
Go
3
star
22

dachs

Compare outputs, send report
Go
3
star
23

usbload

software usb bootloader for various projects
C
3
star
24

termstatus

Go
3
star
25

kahuna

Firmware for kahuna usbasp compatible Atmel AVR programmer
C
2
star
26

lasso

Go
2
star
27

simpleproxy

Go
2
star
28

distriproxy

Go
1
star
29

ghm

Go
1
star
30

diva

Go
1
star
31

tdt-with-state

Go
1
star
32

elmo

Go
1
star