我想下载一些1981年到2000年(20年)的数据集。每10分钟一次。我试着写一个脚本,它会一直调用并下载数据。但我无法完成。我无法检查每个月的闰年和闰日。我的剧本是:

#!/bin/sh
for yr in {1981..2000};do
  for mm in 01 02 03 04 05 06 07 08 09 10 11 12;do
    for dd in {1..31};do
      if [[ $dd -le 9 ]];then nn=0$dd;else nn=$dd;fi
      for tt in 00 10 20 30 40 50; do
        echo wget www.xyz.com/$yy/$mm/$nn/$tt.txt
      done;
     done;
    done;
  done

我怎样才能解决闰年的问题,以及一个月中的几天呢?

最佳答案

这就是它的可能(请注意,此闰年计算仅适用于2100年):

#!/bin/sh
for yr in {1981..2000};do
  for mm in 1 2 3 4 5 6 7 8 9 10 11 12;do
    for dd in {1..31};do
     if [[ $dd -eq 31 ]] && ( [[ $mm -eq 4 ]] || [[ $mm -eq 6 ]] || [[ $mm -eq 9 ]] || [[ $mm -eq 11 ]] )
     then
         continue
     elif ( [[ $dd -gt 28 ]] && [[ $mm -eq 2 ]] && [[ $(( $yr % 4 )) -ne 0 ]] ) || ([[ $dd -gt 29 ]] && [[ $mm -eq 2 ]] )
     then
         continue
     fi

      if [[ $mm -le 9 ]];then mon=0$mm;else mon=$mm;fi

      if [[ $dd -le 9 ]];then nn=0$dd;else nn=$dd;fi
      for tt in 00 10 20 30 40 50; do
        echo wget www.xyz.com/$yy/$mon/$nn/$tt.txt
      done;
     done;
    done;
 done

关于linux - 如何在Shell脚本中生成顺序日期/时间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36394854/

10-16 11:27