Самый легкий путь состоит в том, чтобы установить, Связывают локально. Большая часть установки значения по умолчанию дистрибутивов Связывает, будет non-autoritative только для кэширования.
Просто добавьте a logging {}
блок конфигурации (как описано в Связывании 9 Ссылок Конфигурации) затем установил Вашу систему для использования 127.0.0.1
или ::1
как сопоставитель DNS.
Да.
curl
имеет две опции: --connect-timeout
и --max-time
.
Заключение в кавычки из страницы справочника:
--connect-timeout <seconds>
Maximum time in seconds that you allow the connection to the
server to take. This only limits the connection phase, once
curl has connected this option is of no more use. Since 7.32.0,
this option accepts decimal values, but the actual timeout will
decrease in accuracy as the specified timeout increases in deci‐
mal precision. See also the -m, --max-time option.
If this option is used several times, the last one will be used.
и:
-m, --max-time <seconds>
Maximum time in seconds that you allow the whole operation to
take. This is useful for preventing your batch jobs from hang‐
ing for hours due to slow networks or links going down. Since
7.32.0, this option accepts decimal values, but the actual time‐
out will decrease in accuracy as the specified timeout increases
in decimal precision. See also the --connect-timeout option.
If this option is used several times, the last one will be used.
Здесь (на Debian) это прекращает пытаться соединиться после 2 минут, независимо от времени, указанного с --connect-timeout
и хотя значение тайм-аута подключения по умолчанию, кажется, составляет 5 минут согласно DEFAULT_CONNECT_TIMEOUT
макрос в lib/connect.h.
Значение по умолчанию для --max-time
кажется, не существует, делая curl
ожидайте навсегда ответа, если начальное подключение успешно выполняется.
Вы, вероятно, интересуетесь последней опцией, --max-time
. Поскольку Ваш случай установил его на 900
(15 минут).
Опция Specifying --connect-timeout
к чему-то как 60
(одна минута), могла бы также быть хорошая идея. Иначе curl
попытается соединиться снова и снова, по-видимому, с помощью некоторого алгоритма задержки.
Существует timelimit:/usr/bin/timelimit - эффективно ограничивают абсолютное время выполнения процесса
Options:
-p If the child process is terminated by a signal, timelimit
propagates this condition, i.e. sends the same signal to itself.
This allows the program executing timelimit to determine
whether the child process was terminated by a signal or
actually exited with an exit code larger than 128.
-q Quiet operation - timelimit does not output diagnostic
messages about signals sent to the child process.
-S killsig
Specify the number of the signal to be sent to the
process killtime seconds after warntime has expired.
Defaults to 9 (SIGKILL).
-s warnsig
Specify the number of the signal to be sent to the
process warntime seconds after it has been started.
Defaults to 15 (SIGTERM).
-T killtime
Specify the maximum execution time of the process before
sending killsig after warnsig has been sent. Defaults to 120 seconds.
-t warntime
Specify the maximum execution time of the process in
seconds before sending warnsig. Defaults to 3600 seconds.
On systems that support the setitimer(2) system call, the
warntime and killtime values may be specified in fractional
seconds with microsecond precision.
Лучше чем --макс-времени
являются опции --ограничения скорости
и --ограничения скорости
. Короче говоря, --ограничение скорости
указывает минимальную среднюю скорость, которую вы готовы принять, а --скорость-время
указывает, как долго скорость передачи может оставаться ниже этого предела до истечения времени передачи и прерывается.
Par de soluciones en BASH4+
# -- server available to check via port xxx ? --
function isServerAvailableNC() {
max_secs_run="${3}"
if timeout $max_secs_run nc -z ${1} ${2} 2>/dev/null >/dev/null; then
#echo "${1} ✓"
true
else
#echo "${1} ✗"
return
fi
}
# -- server available to check via port xxx ? --
# -- supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE) --
#/usr/bin/curl -sSf --max-time 3 https://ifwewanted.to.confirm.https.com/ --insecure
function isServerAvailableCURL() {
max_secs_run="${3}"
proto="http://"
if [ ! -z ${2} ] || [ ${2} -gt 80 ] ;then
proto="https://"
fi
if /usr/bin/curl -sSf --max-time "${max_secs_run}" "${1}" --insecure 2>/dev/null >/dev/null; then
#echo "${1} ✓"
true
else
#echo "${1} ✗"
false
fi
}
Ejemplo de uso:
RECOMENDAR QUE se use NC si necesitamos un puerto específico
host="1.2.3.4"
if isServerAvailableCURL "$host" "80" "3";then
check_remote_domain_cert "$host"
fi
host="1.2.3.4"
if isServerAvailableNC "$host" "80" "3";then
check_remote_domain_cert "$host"
fi
Если у вас установлены coreutils в MacOS, вы можете использовать команду тайм-аута GNU, которая включена в этот пакет. Все инструменты GNU имеют префикс g
, поэтому интерфейс командной строки будет gtimeout
.
gtimeout --help
Usage: gtimeout [OPTION] DURATION COMMAND [ARG]...
or: gtimeout [OPTION]
Start COMMAND, and kill it if still running after DURATION.
$ gtimeout 1s curl -I http://www.google.com/
HTTP/1.1 200 OK
Date: Wed, 31 Oct 2018 03:36:08 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2018-10-31-03; expires=Fri, 30-Nov-2018 03:36:08 GMT; path=/; domain=.google.com
HttpOnly
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding