![ダウンロード前にカーリングの長い遅延[閉じる]](https://linux33.com/image/96991/%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89%E5%89%8D%E3%81%AB%E3%82%AB%E3%83%BC%E3%83%AA%E3%83%B3%E3%82%B0%E3%81%AE%E9%95%B7%E3%81%84%E9%81%85%E5%BB%B6%5B%E9%96%89%E3%81%98%E3%82%8B%5D.png)
Webディレクトリにファイルがあることを確認するbashスクリプトがあります。ファイルが存在しない場合は終了します。ファイルがWebディレクトリにある場合はダウンロードされます。
しかし、スクリプトはうまく動作します。 「存在」条件が満たされた後、実際にスクリプト(ライン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
if $?
; then
bash somescript.sh
else
exit 0
fi
@zneakのクレジット