【问题标题】:GNU Parallel echo job numberGNU 并行回显作业编号
【发布时间】:2020-10-10 17:31:16
【问题描述】:

所以我有这个代码:parallel --jobs 5 curl --write-out '\\n %{http_code}\\n' --silent --head --output /dev/null https://example.com/id={} ::: {427240690783..427240690793}

返回 10 批 404。

如果 HTTP 响应代码为 200,我想回显当前作业迭代 ID,显示在 {} 中。我将如何回应这些?

抱歉,我是 GNU 的新手。

【问题讨论】:

    标签: gnu gnu-parallel


    【解决方案1】:

    当命令变得如此复杂时,我通常会生成函数:

    doit() {
      curl --write-out '\n  %{http_code}\n' --silent --head --output /dev/null https://example.com/id="$1"
    }
    export -f 
    parallel doit ::: {427240690783..427240690793}
    

    这是因为很容易测试函数是否对一个输入做正确的事情。当它这样做时,您调用 GNU Parallel 来调用该函数。

    你可能想要这样的东西:

    grep200() {
      status=$(curl --write-out '%{http_code}' --silent --head --output /dev/null "$1"); 
      if [ $status == 200 ] ; then
        echo "$1";
      fi;
    }
    export -f grep200
    parallel grep200 https://example.com/id={} ::: {427240690783..427240690793}
    

    【讨论】:

    • 感谢奥莱!这正是我最终所做的。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多