URL/파일이 존재하는지 확인하고 다운로드하는 방법

URL/파일이 존재하는지 확인하고 다운로드하는 방법

bash에 zip 파일이 있는지 확인하고 다운로드하는 올바른 방법이 있습니까? 파일을 사용할 수 없는 경우 잠시 기다렸다가 사용할 수 있게 되면 다운로드하세요. 예를 들어, x초마다 URL을 확인하고, 사용 가능한 경우 파일을 다운로드하고 종료하고, 그렇지 않으면 다운로드될 때까지 기다립니다. 그것은 다음과 같습니다:

if curl --head --silent --fail -X POST https://192.168.1.2/file/file.zip 2> /dev/null;
then
    wget https://192.168.1.2/file/file.zip
else
    sleep 60 && #check every x seconds and download when available"
fi

감사합니다,

답변1

성공할 때까지 간단히 명령을 다시 실행할 수 있습니다.

while ! wget https://192.168.1.2/file/file.zip; do
    sleep 60
done

답변2

wget확인 및 재시도를 위한 기본 옵션이 있습니다. 다음은 유용하다고 생각되는 옵션 중 일부를 적절하게 결합하는 것입니다.

--spider
           When invoked with this option, Wget will behave as a Web spider, which means that it will not download the pages, just check that they are there.

-w seconds
       --wait=seconds
           Wait the specified number of seconds between the retrievals.  Use of this option is recommended, as it lightens the server load by making the requests less frequent.  Instead
           of in seconds, the time can be specified in minutes using the "m" suffix, in hours using "h" suffix, or in days using "d" suffix.

           Specifying a large value for this option is useful if the network or the destination host is down, so that Wget can wait long enough to reasonably expect the network error to
           be fixed before the retry.  The waiting interval specified by this function is influenced by "--random-wait", which see.
    enter code here

-t number
       --tries=number
           Set number of tries to number. Specify 0 or inf for infinite retrying.  The default is to retry 20 times, with the exception of fatal errors like "connection refused" or "not
           found" (404), which are not retried.

이런 게 더 있어요man wget

관련 정보