[英]Downloading most recent file using curl
我需要使用 curl 從遠程站點根據文件創建時間下載最新文件。 我怎樣才能實現它?
這些是遠程站點中的文件
user-producer-info-etl-2.0.0-20221213.111513-53-exec.jar
user-producer-info-etl-2.0.0-20221212.111513-53-exec.jar
user-producer-info-etl-2.0.0-20221214.111513-53-exec.jar
user-producer-info-etl-2.0.0-20221215.111513-53-exec.jar
以上 user-producer-info-etl-2.0.0-20221215.111513-53-exec.jar 是我要下載的最新文件嗎? 我怎樣才能實現它?
幸運的是,文件名包含可按字母順序排序的日期!
我不知道你在哪里,所以我猜你至少有一個 shell,我建議這個 bash 答案:
首先獲取最后一個文件名
readonly endpoint="https://your-gitlab.local"
# Get the last filename
readonly most_recent_file="$(curl -s "${endpoint}/get_list_uri"|sort|tail -n 1)"
# Download it
curl -LOs curl "${endpoint}/get/${most_recent_file}"
您顯然需要相應地替換網址,但我相信您明白了
-L
:遵循 HTTP 302 重定向-O
:將文件下載到本地目錄,保持名稱不變-s
:靜默不顯示網絡時間和東西您還可以使用-o <the_most_recent_file>
指定另一個本地名稱
了解更多信息:
man curl
hth
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.