这个问题在上一篇文章中因不够清晰而被关闭,我可以选择编辑或重新发布这个问题。我决定转发这个问题,这样其他可能以前看过的人就可以再次看到它,但更清晰。谢谢
我在Sharepoint在线文档库中有一个文件夹(例如FOLDERX(,在那里我使用microsoftgraph API通过FILENAME获取文件
MS图形API:https://graph.microsoft.com/v1.0/drives/{驱动器id}/root:/filename.txt:/content
注意:这些API只能通过其文件名获取文件。文件每天都是相同的通用文件名,所以我知道期望的文件名,因此,我可以很容易地在API调用中使用文件名
我每天运行一次使用cURL获取这些文件的cron作业
因此例如如果每天被PUT在文件夹中的文件是"PUT";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
现在,通用文件名不再通用了。文件名现在要么是";文件.csv";或";文件B.csv";。每天都有一个,我不能每天都在API调用上手动编辑文件名。
因此,我试图编写一个IF语句,首先检查每天Sharepoint Online文件夹(FOLDERX(上有什么文件名可用,这样当脚本运行时,API curl就会知道使用API curl 获取哪个文件名
以下是我在尝试了一周多不同的IF语句场景后的情况。API调用运行良好。请,我只需要帮助写一个IF语句,检查远程Sharepoint Online文件夹,看看有什么文件名,然后使用API调用cURL。
#!/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
EDIT:我不知道如何编写IF语句,这就是我把它带到这里的原因。
只需同时尝试这两种方法,使用--fail
使curl
在获得404、503或类似值时通知shell。
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; }