Skip to content

Instantly share code, notes, and snippets.

@hardiksondagar
Created March 22, 2019 05:57
Show Gist options
  • Save hardiksondagar/6e433bae8a0cb12498a2413b269fb72e to your computer and use it in GitHub Desktop.
Save hardiksondagar/6e433bae8a0cb12498a2413b269fb72e to your computer and use it in GitHub Desktop.
Looping through dates in shell script
#!/bin/bash -l
# loop-dates.sh 2019-02-01 2019-03-01
start_time=`date +"%Y-%m-%d" -d $1`
end_time=`date +"%Y-%m-%d" -d $2`
dt=$start_time
while [ "$dt" != "$end_time" ] ;
do
start=`date '+%Y-%m-%d %T' -d "$dt"`;
end=`date '+%Y-%m-%d %T' -d "$dt +1 day"`;
echo $start, $end
python your-awesome-script.py --start_time="$start" --end_time="$end"
dt=`date +"%Y-%m-%d" -d "$dt +1 day"`;
sleep 1s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment