【问题标题】:Using if else and xargs to pipe into gnu parallel使用 if else 和 xargs 并行管道到 gnu
【发布时间】:2017-09-27 06:26:38
【问题描述】:

使用 if else 和 xargs 并行管道进入 gnu(对其他建议开放,查找...)

简而言之,我正在尝试编写一个脚本来检查现有文件夹并在 gnu 并行运行命令(不存在的文件夹/文件的脚本)(对其他建议开放)

我将为主题/文件列表运行脚本,它们将分布在服务器上的多个计算节点上,因此该命令不要再次覆盖现有文件夹,因为相同的脚本将被在不同的节点上运行,并且它们都指向相同的目录。到目前为止,我的想法如下:

为了简单

SUBJ_LIST=(a text file with list of subjects/files to be executed .txt)
SUBJ_EXIST=(folder that the program outputs to)
SUBJ_tp_do= (hopefully only subjects/files that have not been done)

cat ${SUBJ_LIST} | xargs -I{} -n 1 if [ -d ${SUBJ_EXIST}/{} ]
then
   echo "folder exists"
else
   SUBJ_tp_do={}
fi

parallel -j8 command {}  ::: ${SUBJ_to_do}

你可以说这个脚本不起作用

对于我在脚本方面的基本知识提前道歉,非常感谢任何帮助/输入。

【问题讨论】:

    标签: if-statement pipe xargs gnu-parallel


    【解决方案1】:

    我不是 100% 清楚你想做什么。

    我假设您要处理文件foo,完成后输出在bar/foo 中。所以如果bar/foo 存在,你就不想运行process foo

    为此,GNU Parallel 有--resume--results

    $ parallel --results bar/{} --resume -v echo  ::: a b c
    echo a
    a
    echo b
    b
    echo c
    c
    $ parallel --results bar/{} --resume -v echo  ::: a b c
    <<no output - nothing was run>>
    $ parallel --results bar/{} --resume -v echo  ::: 1 a b 2 3 c
    echo 1
    1
    echo 2
    2
    echo 3
    3
    

    注意在上次运行中如何跳过 a、b 和 c。

    如果 a、b 和 c 在文件中,则只需替换为:

    parallel ... :::: inputfile.txt
    

    【讨论】:

    • 美女!完美地工作是的,这正是我想做的。我不知道parallel内置了这个功能。谢谢!
    猜你喜欢
    • 2012-04-05
    • 1970-01-01
    • 2014-03-11
    • 2014-07-19
    • 1970-01-01
    • 2017-01-14
    • 2017-09-09
    • 2021-07-15
    • 1970-01-01
    相关资源
    最近更新 更多