はじめに

この資料は Rust 製のコマンドラインツール async-cmd について紹介するものです。

Rustの環境構築やツールのインストール方法については以下を参照してください

Rust開発環境を整える

async-cmd について

async-cmd はシェルコマンドを並列に実行するためのツールです。コマンド名は async です。 最小限の変更でシェルスクリプトを素早く並列化できるように設計されています。GNU Parallel に触発されたものですが、主な違いは async がバックグラウンドでサーバを実行することにより、コマンド間の状態を保持する点です。

GitHub - ctbur/async: A tool to parallelize shell commands.

使用例

#!/bin/bash
S="/tmp/example_socket"

async -s="$S" server --start

for i in {1..20}; do
    # prints command output to stdout
    async -s="$S" cmd -- bash -c "sleep 1 && echo test $i"
done

# wait until all commands are finished
async -s="$S" wait

# configure the server to run four commands in parallel
async -s="$S" server -j4

mkdir "/tmp/ex_dir"
for i in {21..40}; do
    # redirects command output to /tmp/ex_dir/file*
    async -s="$S" cmd -o "/tmp/ex_dir/file$i" -- bash -c "sleep 1 && echo test $i"
done

async -s="$S" wait

# stops server
async -s="$S" server --stop

ドキュメント

ライセンス