我正在尝试自动下载我们学校的天气数据。我不是一个技术高超的人,但我想我是学校里最好的。我的问题是尝试将时间变量插入网址。这是我到目前为止所做的。
目前这有效:
curl -o /Library/Server/Web/Data/Sites/wupmooksgmol.ca/weather/"$(date +%Y)"/"$(date +%Y-%m-%d)".weather.csv 'http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IBRITISH322&day=16&month=1&year=2015&graphspan=day&format=1'
但是,在网址中,它只下载了 2015 年 1 月 16 日的天气数据。我想将当前日期、月份和年份放入网址本身。因此,它会在每天 23:57 下载当天的天气数据。我在以下方面尝试了很多变化,但没有运气:
curl -o /Library/Server/Web/Data/Sites/wupmooksgmol.ca/weather/"$(date +%Y)"/"$(date +%Y-%m-%d)".weather.csv 'http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IBRITISH322&day=“$(date +%d)”&month=“$(date +%m)”&year=“$(date +%Y)”&graphspan=day&format=1'
我还尝试了这个 shell 脚本的多种变体:
#!/bin/bash
day=$(date '+%d')
month=$(date '+%m')
year=$(date '+%Y')
ymd=$(date '+%Y-%m-%d')
curl -o /Library/Server/Web/Data/Sites/wupmooksgmol.ca/weather/“$year"/"$ymd".weather.csv 'http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IBRITISH322&day=“$day”&month=“$month”&year=“$year”&graphspan=day&format=1'
感谢您的任何帮助,您可以提供。