2

現在、スクリプトから約 100 個のファイルを生成しています。これらのファイルを 20 個のバッチで反復処理し、別のスクリプトを使用して実行し、完了したらファイルを削除します (クリーンアップ)。GNU Parallel でこれを実行できると思いますしかし、これを行う方法が正確にはわかりませんか?

# test if files exists and run
if [ "$(ls -A ${base_dir}/schedule)" ]; then

    while [ "$(ls -A ${base_dir}/schedule)" ]; do

        # current run of 20 files
        batch=`ls ${base_dir}/schedule | head -n 20`

        # parallel run on 4 processors
        parallel -j4 ./script.sh ${batch} ::: {1..20}

        # cleanup
        for file in "${batch}"; do
            rm "${base_dir}/schedule/${file}"
        done

    done
fi

期待される出力は次のようになります

# running first batch of twenty
 ./scipt.sh 1466-10389-data.nfo # after file has finished, rm 1466-10389-data.nfo
 ./scipt.sh 1466-10709-data.nfo # etc
 ./scipt.sh 1466-11230-data.nfo # etc
 ./scipt.sh 1466-11739-data.nfo
 ./scipt.sh 1466-11752-data.nfo
 ./scipt.sh 1466-13074-data.nfo
 ./scipt.sh 1466-14009-data.nfo
 ./scipt.sh 1466-1402-data.nfo
 ./scipt.sh 1466-14401-data.nfo
 ./scipt.sh 1466-14535-data.nfo
 ./scipt.sh 1466-1588-data.nfo
 ./scipt.sh 1466-17012-data.nfo
 ./scipt.sh 1466-17611-data.nfo
 ./scipt.sh 1466-18688-data.nfo
 ./scipt.sh 1466-19469-data.nfo
 ./scipt.sh 1466-19503-data.nfo
 ./scipt.sh 1466-21044-data.nfo
 ./scipt.sh 1466-21819-data.nfo
 ./scipt.sh 1466-22325-data.nfo
 ./scipt.sh 1466-23437-data.nfo

# wait till all are finished, OR queue up next file so  all times
# twenty files are running at until the directory is empty
4

2 に答える 2