dsj1961061 2016-01-31 08:59
浏览 91
已采纳

循环bash脚本,直到cURL响应不等于字符串

I'm trying to loop a bash script (cURL below) until my remote PHP script doesn't equal failure. I've tried the following, and it works when $fileName exists.. but doesn't loop when it returns failure.

My PHP:

<?php
$videoFile = $_GET["name"] . ".mp4";
if (file_exists($videoFile)) {
    echo "success";
} else {
    echo "failure";
}
?>

Bash command:

until $(curl --output /dev/null --silent --head --fail "my-remote-php-script.php"); do
    printf '.'
    sleep 1
done
  • 写回答

2条回答 默认 最新

  • dongyinpan9284 2016-01-31 09:07
    关注

    This should work:

    while [ "$(curl -s 'http://your-url.php')" == "failure" ]; do
      echo -n '.'
      sleep 1
    done
    

    The $() places the curl in a sub-shell. The resulting string, comming from your php script, is compared with failure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部