我目前正在从我的脚本中生成大约 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