Skip to content
Snippets Groups Projects
do_by_day.sh 726 B
Newer Older
Guillaume S's avatar
Guillaume S committed
#!/bin/bash

set +xv

# ARGUMENTS
date_beg=$1
date_end=$2
script=$3
script_arg=$4


# TIME
year_beg=${1:0:4}
year_end=${2:0:4}
mnth_beg=${1:4:2}
mnth_end=${2:4:2}
day_beg=${1:6:2}
day_end=${2:6:2}

if [ -z ${day_beg} ]; then
  day_beg=01
  date_beg=${date_beg}${day_beg}
fi

if [ -z ${day_end} ]; then
  day_end=$( date -d "${mnth_end}/1 + 1 month - 1 day" "+%d" )
  date_end=${date_end}${day_end}
fi

nb_day=$(( ($(date --date="${date_end}H00 + 1 day" +%s) - $(date --date="${date_beg}H00" +%s) ) / (60*60*24)  ))
echo $date_beg $date_end $nb_day

Guillaume S's avatar
Guillaume S committed
for (( d=0; d<$nb_day; d++ )); do
Guillaume S's avatar
Guillaume S committed

  date_day=$(date -d "$date_beg + $d days" +%Y%m%d)
Guillaume S's avatar
Guillaume S committed
  echo $script $date_day $script_arg
  ${script} ${date_day} ${script_arg}
Guillaume S's avatar
Guillaume S committed

done


exit 0