【问题标题】:Time out a curl command shell script centOS超时一个 curl 命令 shell 脚本 centOS
【发布时间】:2019-01-21 23:55:12
【问题描述】:
checkServer(){
    response=$(curl --connect-timeout 10  --write-out %{http_code} --silent --output /dev/null localhost:8080/patuna/servicecheck)

    if [ "$response" = "200" ];
        then echo "`date --rfc-3339=seconds` -  Server is healthy, up and running"
        return 0
    else
        echo "`date --rfc-3339=seconds` -  Server is not healthy(response code - $response ), server is going to restrat"
        startTomcat
    fi
}

在这里我想使 curl 命令超时,但它不起作用。在 centos7 Shell 脚本中。我只需要让 curl 命令超时 错误代码是 curl: option --connect-timeout=: is unknown

【问题讨论】:

  • Shell 是一种编程语言。我认为 StackOverflow 或 Super User 或 Unix & Linux Stack Exchange 都适合提问。

标签: linux shell curl timeout sh


【解决方案1】:

你可以试试--max-time这个选项。

允许整个操作花费的最长时间(以秒为单位)。这对于防止您的批处理作业因网络或链接速度慢而挂起数小时很有用 下降。从 7.32.0 开始,此选项接受十进制值,但实际超时的准确性会随着指定超时的十进制精度增加而降低。

如果你只是想检查 http 状态码。您可能想查看--head 选项。

我建议同时使用--silent--show-error,以防您可能想知道错误消息。

【讨论】:

    【解决方案2】:
    checkServer(){
            response=$(curl --max-time 20 --connect-timeout 0  --write-out %{http_code} --silent --output /dev/null localhost:8080/patuna/servicecheck)
    
            if [ "$response" = "200" ];
               then echo "`date --rfc-3339=seconds` -  Server is healthy, up and running"
               return 0
            else
               echo "`date --rfc-3339=seconds` -  Server is not healthy(response code - $response ), server is going to restrat"
               startTomcat
            fi
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 2014-12-13
      相关资源
      最近更新 更多