我正在使用 openphoto 从 bash 脚本上传照片。有时上传会失败,但所有命令都能正确执行。 json 结果提供:
{
"message" : "oauth_problem=signature_invalid&debug_sbs=POST&http...,
"code" : 403,
"result" : null
}
上传失败,因为正在上传的照片位于远程服务器上,并且在上传到 openphoto 之前有时无法正确缓存文件。通常只需重复该命令即可正确执行。
我的 bash 循环如下所示:
while read i;
do ./openphoto -p -X POST -h HOSTNAME -e /photo/upload.json \
-F"photo=@$i" \
-F"tags=$(echo "$i"|cut -d'/' -f 7-|sed 's/\/[^/]*[jJ][pP][gG]//;s/\//,/g')";
done < files;
如果输出包含“代码”403,如何让 bash 重复该命令?
最佳答案
How can I get bash to repeat the command if the output contains a "code" of 403?
您可以在完成
之前添加一行:
(( $? == 403 )) && command_to_execute
或者,如果您想尝试该命令直到成功,您可以说:
until (( $? == 0 )); do command_to_execute; done
关于linux - 在 bash 脚本中重复 curl 命令以获得特定输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19495410/