I want to download a bunch of files named with ISO-8601 dates. Is there a simple way to do this using bash+GNU coreutils? (Or some trick to make wget/curl to generate the list automatically, but I find that unlikely)
Similar to this question, but not restricted to weekdays: How to generate a range of nonweekend dates using tools available in bash?. I guess that there is a simpler way to do it without that restriction.
Also related to How to generate date range for random data on bash, but not restricted to a single year.
Using GNU date and bash:
I use this handy function to work with log files in the format yyyymmdd.log.gz:
It accepts dates in the format yyyymmdd.
If you have GNU
date
, you could do use either afor
loop in any POSIX-compliant shell:or an
until
loop, this time using Bash's extended test[[
:Note that non-ancient versions of
sh
will also do lexicographical comparison if you change the condition to[ "$d" \> 2014-07-03 ]
.Output from either of those loops:
For a more portable way to do the same thing, you could use a Perl script:
Time::Piece, Time::Seconds and File::Fetch are all core modules. Use it like
perl wget.pl 2014-06-29 2014-07-03
.This is how I ended up doing it:
This tries to download all files from today's date until we get a 404.