超时curl命令shell脚本centOS

时间:2018-08-15 04:37:29

标签: linux shell curl timeout sh

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 scrit中。我只需要做的就是超时curl命令     错误代码为curl:选项--connect-timeout =:未知

2 个答案:

答案 0 :(得分:1)

您可以尝试选择--max-time

  

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

如果您只想查看http状态代码。您可能要签出@Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { createDbIfNotExists(); SqlArguments args = new SqlArguments(uri, selection, selectionArgs); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(args.table); qb.setStrict(true); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder); result.setNotificationUri(getContext().getContentResolver(), uri); return result; } 选项。

如果您想了解错误消息,建议同时将--head--silent一起使用。

答案 1 :(得分:0)

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
}