Одновременно запускать curl и таймер процесса

вы запускаете его как администратор / root, когда дважды щелкаете по нему?

когда вы запускаете его с консоли, вы использовали sudo , и это означает, что вы запускают файл как admin / root

0
05.06.2018, 21:13
2 ответа

Está pensando demasiado en las cosas y es posible que no esté al tanto de algunas funciones -integradas quebash(que, dado que no está especificando, supondré que su shell )proporciona:

retries=0
timeout=90
duration=0
complete=0
maxretries=3
while [[ 0 -eq "$complete" ]]; do
    curl -K $conf/appdCurlConfig $prodc $base1d $base3d $base1w $base2w -o $prodCurl -o $base1dCurl -o $base3dCurl -o $base1wCurl -o $base2wCurl &
    curlpid=$! # capture PID of curl command
    while [[ "$timeout" -gt "$duration" ]] && kill -0 $curlpid 2> /dev/null; do
        sleep 1
        duration=$((duration+1))
        case $duration in
            3) 
                echo "It's taking a bit longer.."
                ;;
            30|45|75)
                echo "It's taking a real long time but we'll keep waiting"
                ;;
            85)
                echo "We're about to give up"
                ;;
            $timeout)
                echo "We're giving up."
                kill -TERM $curlpid
                retries=$((retries+1))
                if [[ "$retries" -ge "$maxretries" ]]; then
                    complete=1
                fi
                ;;
        esac
    done
    if wait $curlpid; then
        complete=1 # curl returned non-error; we're done!
    fi
done

kill -0enviará una señal nula; se puede usar para ver si un proceso realmente existe sin afectarlo realmente. El shell capturará el PID de una tarea en segundo plano en $!. Y su escalera if..elifes un ejemplo de libro de texto de algo que colapsa en una declaración case..esac.

1
28.01.2020, 02:43

Если вы можете принять информацию о прогрессе, это не так красиво:

parallel --retries 3 --timeout 10 curl ::: url &&
  echo success ||
  echo failed

Пример:

$ parallel --retries 3 --timeout 10 curl ::: 10.1.1.1 &&
    echo success ||
    echo failed
parallel: Warning: This job was killed because it timed out:
parallel: Warning: curl 10.1.1.1
parallel: Warning: This job was killed because it timed out:
parallel: Warning: curl 10.1.1.1
parallel: Warning: This job was killed because it timed out:
parallel: Warning: curl 10.1.1.1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:10 --:--:--     0failed
0
28.01.2020, 02:43

Теги

Похожие вопросы