If you have a GNU date , you can use any for loop in any POSIX-compatible shell :
# with "for" for i in {1..5}; do echo $(date -I -d "2014-06-28 +$i days") done
or until loop, this time using the advanced test Bash [[ :
# with "until" d="2014-06-29" until [[ $d > 2014-07-03 ]]; do echo "$d" d=$(date -I -d "$d + 1 day") done
Note that non-ancient versions of sh will also perform lexicographic comparisons if you change the condition to [ "$d" \> 2014-07-03 ] .
The output from any of these loops:
2014-06-29 2014-06-30 2014-07-01 2014-07-02 2014-07-03
For a more portable way to do the same, you can use the Perl script:
use strict; use warnings; use Time::Piece; use Time::Seconds; use File::Fetch; my ($t, $end) = map { Time::Piece->strptime($_, "%Y-%m-%d") } @ARGV; while ($t <= $end) { my $url = "http://www.example.com/" . $t->strftime("%F") . ".log"; my $ff = File::Fetch->new( uri => $url ); my $where = $ff->fetch( to => '.' );
Time :: Piece, Time :: Seconds and File :: Fetch are the main modules. Use it as perl wget.pl 2014-06-29 2014-07-03 .
source share