Life Hack

curl retry


curl --connect-timeout 5 \
     --max-time 10 \
     --retry 5 \
     --retry-delay 0 \
     --retry-max-time 60 \
     'http://www.site.com/download/file.txt'

|<---0---->| {<---1---->|  |<---2---->|    |<---3---->|   |<---4---->|   }            |<---5---->|
|....==    | {...==     |  |....==    |    |.....|        |..=== =   |   }
             {

NOTATION
=====  downloading...       (file size is 5)
.....  --connect-timeout 5
|<->|  --max-time 10
<-5->  --retry 5
>| |<  --retry-delay 0      ([default] exp backoff algo)
{   }  --retry-max-time 60  (GAME OVER)


NOTE
retry delay 1, 2, 4, 8 ...
retry #3 connect timeout
retry #5 never happen
download failed at END (71 sec)

Bash script template