dsj1961061 2016-01-31 16:59
浏览 90
已采纳

循环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 17: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条)

报告相同问题?

悬赏问题

  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案