I need to read an existing URL of a JSON document, save it to a file, and commit that file to a git repo on a daily schedule. This seems easier than it's appearing so far, to me.
I'm assuming some sort of Cron job or scheduler, but I haven't been able to find a good solution.
The solution seems to be rather simple:
#!/bin/sh
set -e
cd /path/to/repository
curl -LOR http://$URL/file.json # download the file
git add file.json
git commit -m "file.json at $(date +%Y-%m-%d)"
file.json
is just a placeholder, put the real filename in your script. date +%Y-%m-%d
generates the current date for commit message.
You can use wget
instead of curl
:
wget -O file.json http://$URL/file.json
Make the script executable and call it from cron:
0 9 * * * /path/to/the/script
This calls the script at 9:00 every day.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.