この資料は Rust 製のコマンドラインツール async-cmd について紹介するものです。
Rustの環境構築やツールのインストール方法については以下を参照してください
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
async のヘルプメッセージ
% async --help
async 0.1.1
Cyrill Burgener <[email protected]>
Run your shell commands in parallel.
USAGE:
async --socket <socket-path> <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-s, --socket <socket-path> The socket used for communication
SUBCOMMANDS:
cmd Submit a command to the server
help Prints this message or the help of the given subcommand(s)
server Configure the server
wait Wait for the completion of several commands