带循环的脚本Bash Curl,用于文件夹内的几个文件

时间:2018-11-20 15:23:00

标签: curl

我知道这方面有很多话题,但是每次我的问题都不一样。

我需要在几个文件夹中的本地存储几个文件。

  • 示例:第一个路径是:myWebsite / Myfolder / dateOfToday / File
  • 下一个:myWebsite / Myfolder2 / dateOfToday / file
  • 之后:myWebsite / Myfolder3 / dateOfToday / file

我想使用带有curl的脚本bash,但是我是新手。

所以我想编写一个脚本,每天将每个文件保存在本地存储库中。

感谢您的回答。祝你有美好的一天

1 个答案:

答案 0 :(得分:0)

#!/bin/bash

# get todays date
today=$(date +%Y%m%d)
# directory of site
site_dir='myWebsite'

# loop through the existing directories to find the highest numbered directory
for dir in $(ls myWebsite)
do
    number=$(echo $dir | sed 's/Myfolder//')
    if [[ "${number}" -gt "${highest}" ]]; then
        high_number="${number}"
    fi
done

# add 1 to the highest number we found
# this will be the number of the new directory we create
new_high_number=$((high_number+1))

# build our new path
new_path=""${site_dir}"/Myfolder"${new_high_number}"/"${today}"/"

# create the dir
mkdir -p "${new_path}"

# curl your file and put it in the new directory
curl -i "${new_path}" http://some-site.com/some-file.json