由于之前的帖子中缺乏明確性,該問題已關閉,我可以選擇編輯或重新發布該問題。我決定重新發布這個問題,以便以前可能看過它的其他人可以再次看到它,但更清晰。謝謝
我在 Sharepoint Online 檔案庫中有一個檔案夾(例如 FOLDERX),我在其中使用 microsoft graph API 通過他們的FILENAME獲取檔案
MS 圖形 API:https ://graph.microsoft.com/v1.0/drives/{drive-id}/root:/filename.txt:/content
注意:這些 API 只能通過檔案名獲取檔案。這些檔案每天都是相同的通用檔案名,因此我知道預期的檔案名,因此我可以輕松地在 API 呼叫中使用檔案名
我每天運行一次使用 cURL 獲取這些檔案的 cron 作業
因此,例如,如果每天放入檔案夾中的檔案是“FileA.csv”,則 API 呼叫我的 in 腳本將如下所示,然后將檔案輸出到腳本運行的遠程 ubuntu 服務器
#!/bin/bash
TOKEN=$(<curl command to retrieve the token needed for the api call>)
#api call that from sharepoint online that outputs to a csv file on remote server
curl -L -X GET "https://graph.microsoft.com/v1.0/drives/<driveID>/root:/FOLDERX/FileA.csv:/content" -H "Authorization: Bearer ${TOKEN}" > FileA.csv
現在,那個通用檔案名不再是通用的了。檔案名現在是“FileA.csv”或“FileB.csv”。它是每天一個,我不能每天在我的 API 呼叫上手動編輯檔案名。
所以我試圖撰寫一個 IF 陳述句,首先每天檢查 Sharepoint Online 檔案夾(FOLDERX)上可用的檔案名,所以當腳本運行時,API curl 知道使用 API curl 獲取哪個檔案名
下面是我在嘗試不同的 IF 陳述句場景一個多星期后所處的位置。API 呼叫運行良好。請幫助我撰寫一個 IF 陳述句來檢查遠程 Sharepoint Online 檔案夾以查看存在的檔案名,然后使用 API 呼叫將其卷曲。
#!/bin/bash
TOKEN=$(<curl command to retrieve the token needed for the api call>)
if [ <not sure what to put in here> ];
then
curl -L -X GET "https://graph.microsoft.com/v1.0/drives/<driveID>/root:/FOLDERX/FileA.csv:/content" -H "Authorization: Bearer ${TOKEN}" > FileA.csv
else
curl -L -X GET "https://graph.microsoft.com/v1.0/drives/<driveID>/root:/FOLDERX/FileB.csv:/content" -H "Authorization: Bearer ${TOKEN}" > FileA.csv
fi
編輯:我不知道如何撰寫 IF 陳述句,這就是我在這里提出它的原因。
uj5u.com熱心網友回復:
兩者都試一下,--fail用來curl讓 shell 知道它什么時候得到 404、503 或類似的。
curl --fail -L -X GET "https://graph.microsoft.com/v1.0/drives/<driveID>/root:/FOLDERX/FileA.csv:/content" -H "Authorization: Bearer ${TOKEN}" >File.csv \
|| curl --fail -L -X GET "https://graph.microsoft.com/v1.0/drives/<driveID>/root:/FOLDERX/FileB.csv:/content" -H "Authorization: Bearer ${TOKEN}" >File.csv \
|| { echo "ERROR: Could not retrieve either FileA or FileB" >&2; exit 1; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/512681.html
