Curl 다운로드 전 오랜 지연

Curl 다운로드 전 오랜 지연

웹 디렉토리에 파일이 있는지 확인하는 bash 스크립트가 있습니다. 파일이 존재하지 않으면 단순히 종료됩니다. 해당 파일이 웹 디렉터리에 있으면 해당 파일을 다운로드합니다.

스크립트는 올바르게 작동하지만 "존재" 조건을 충족한 후 스크립트가 실제로 트리거되기 전(라인 4) 5분 이상의 지연 시간을 측정했습니다.

이 스크립트에서 스크립트 실행을 지연시키는 뭔가가 누락되었나요?

Bash 스크립트 코드:

url="http://website.url/directory/file.txt"

if curl -f ${url} >/dev/null 2>&1; then
  bash some_bash_script.sh
else
  exit 0
fi

답변1

wget --spider나는 결국 curl.

수정된 Bash 스크립트:

url="http://website.url/directory/file.txt"

if wget --spider ${url} >/dev/null 2>&1; then
  bash some_bash_script.sh
else
  exit 0
fi

답변2

다음과 같이 할 수도 있습니다.

curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
# on success (page exists), $? will be 0; on failure (page does not exist or
# is unreachable), $? will be 1

원천:https://stackoverflow.com/questions/2924422/how-do-i-determine-if-a-web-page-exists-with-shell-scripting

if $?
; then
  bash somescript.sh
else
  exit 0
fi

@zneak에 대한 크레딧

관련 정보