仅当 Progress = 100% 或 status = Complete 时才继续执行下一个 cURL 语句,否则等待其达到 100%

仅当 Progress = 100% 或 status = Complete 时才继续执行下一个 cURL 语句,否则等待其达到 100%

我正在尝试自动化一段 cURL 代码。我陷入了这一步,需要确保percentComplete = 100% 或status = Complete 才能继续。这是 i/p -

curl -XGET -H 'X-API-TOKEN: xxxxxxxxxxxxxxxxxxxx' -H 'Content-Type: application/json' https://xx1.qualtrics.com/API/v3/surveys/XX_XXXXXXXXXXX/export-responses/XX_XXXXXXXXX

这是输出 -

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   188  100   188    0     0    541      0 --:--:-- --:--:-- --:--:--   540{"result":{"fileId":"xxx-xxx-xxx-xxx-xxx","percentComplete":100.0,"status":"complete"},"meta":{"requestId":"xxx-xxx-xxx-xxx-xxx","httpStatus":"200 - OK"}}

我尝试使用正则表达式来提取状态并将其与“完整”进行比较,如下所示 -

while [$(curl -XGET -H 'X-API-TOKEN: xxxxxxxxxxxxxxxxxxxx' -H 'Content-Type: application/json' https://xx1.qualtrics.com/API/v3/surveys/XX_XXXXXXXXXXX/export-responses/XX_XXXXXXXXX | sed -E -n 's/.*status":"([a-z]+).+/\1/p')!= "complete"]; 
do sleep 5s;
done

答案1

我使用了评论中的建议,并创建了以下对我有用的内容 - 注意 - $VAR 是我在这里使用的上一个命令的输出。

VAR2="$(curl -f -XGET -H 'X-API-TOKEN: XXXXXXXXX' -H 'Content-Type: application/json' https://xxx.qualtrics.com/xx_xxxxxxx/export-responses/"$VAR" | sed -E -n 's/.*status":"([a-z]+).+/\1/p')"
echo $VAR2
#sleep 10s
a=1
while [ $a = 1 ]
do
    if [ $VAR2 != 'complete' ]
    then
        VAR2="$(curl -f -XGET -H 'X-API-TOKEN: xxxxxxxxxxxx' -H 'Content-Type: application/json' https://xx.qualtrics.com/xxxxxxxxx/export-responses/"$VAR" | sed -E -n 's/.*status":"([a-z]+).+/\1/p')"
        sleep 3s
    else
        a=`expr $a + 2`
    fi
done 

相关内容