
我有四個 Raspberry Pie 都運行curl 7.64.0。每個 Pi 每兩分鐘就會將網路攝影機影像上傳到同一主機。四個 Pie 每小時 30 張圖像。這一切都是透過簡單的 bash shell 腳本完成的。與主機的身份驗證是透過公鑰完成的。
通常情況下這工作正常,但有時所有或大多數 Pies 都會失敗並出現curl 錯誤 2,根據日誌,這是由以下原因引起的:「建立 ssh 會話失敗:-13,獲取橫幅失敗」。
我知道這不是由curl 錯誤引起的,但是,我想知道是否有某種方法可以克服curl 的錯誤。
現在我正在使用以下參數:
--connect-timeout 10 --max-time 120 --retry 5 我將 max-time 設定為 120,因為圖像每兩分鐘上傳一次。另外兩個只是我對可能有效的猜測。
這是完整的curl指令:
curl -s -v -u me: \
--connect-timeout 10 \
--max-time 120 \
--retry 5 \
--pubkey ~/.ssh/id_rsa.pub \
-T $file $host >> $log 2>&1
在哪裡:
$file is: the file to be uploaded
$host is: host=sftp://ftp.me.com/~/public_html/
$log is: the local log file
這是詳細的捲曲輸出:
* Trying nnn.nnn.nnn.nnn...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x3698b0)
* Connected to ftp.mgnewman.com (nnn.nnn.nnn.nnn) port 22 (#0)
* Failure establishing ssh session: -13, Failed getting banner
* Closing connection 0
有沒有更好的辦法?
答案1
這不是問題的答案,但它是問題的一種解決方案。我用 do 迴圈包圍了curl 指令。看來curl並沒有將「Failed gettingbanner」錯誤視為連線錯誤,因此它不會「重試」;它只是超時了。這是我正在使用的:
for i in {1..3}
do
curl -s -v -u mgnewman: \
--connect-timeout 25 \
--max-time 40 \
--retry 3 \
--pubkey ~/.ssh/id_rsa.pub \
-T $file $host >> $log 2>&1
err=$?
echo $'\n'"`date`" Upload Ended "$err" - $(hostname) >> "$log"
if [ $err -eq 0 ] ; then
break
fi
done
雖然很難看,但四個 Pie 中的任何一個都不再出現curl 2 錯誤。