I am trying to loop over a date range and have copied the answer on this post.
My script 'loop_run_local.sh':
d=2019-11-12
while [ "$d" != 2019-11-14 ]; do
echo 'Starting Data Extract...'
echo 'run date is: ' $d
echo 'Starting Transactions Extract...'
python3.7 flagship_ecom/run_transactions.py $d
d=$(date -I -d "$d + 1 day")
done
This seems to work for the first iteration only, not subsequent dates so I guess something is not working with d=$(date -I -d "$d + 1 day")
?
Terminal output before I hit ctrl+z to stop the loop:
bash-3.2$ ./flagship_ecom/loop_run_local.sh
Starting Data Extract...
run date is: 2019-11-12
Starting Transactions Extract...
pageToken is:0 : 2019-11-12
/Users/macuser/Library/Python/3.7/lib/python/site-packages/tqdm/std.py:658: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version
from pandas import Panel
Pandas Apply: 100%|██████████████████████████████████████████████████████████████████████████████| 2737/2737 [00:00<00:00, 3156.76it/s]
date: illegal option -- I
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Starting Data Extract...
run date is:
Starting Transactions Extract...
Traceback (most recent call last):
File "flagship_ecom/run_transactions.py", line 17, in <module>
start_date = sys.argv[1]
IndexError: list index out of range
date: illegal option -- I
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Starting Data Extract...
run date is:
Starting Transactions Extract...
Traceback (most recent call last):
File "flagship_ecom/run_transactions.py", line 17, in <module>
start_date = sys.argv[1]
IndexError: list index out of range
date: illegal option -- I
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Starting Data Extract...
run date is:
Starting Transactions Extract...
^Z
[2]+ Stopped ./flagship_ecom/loop_run_local.sh
This line in the output:
run date is: 2019-11-12
Corresponds to this line within the .sh script:
echo 'run date is: ' $d
Since this is blank on dates after the starting date, I presume there's an issue with my incrementing of the date?
Here is the output when prefixed with bash -x per comments:
bash-3.2$ bash -x ./flagship_ecom/loop_run_local.sh
+ d=2019-11-12
+ '[' 2019-11-12 '!=' 2019-11-14 ']'
+ echo 'Starting Data Extract...'
Starting Data Extract...
+ echo 'run date is: ' 2019-11-12
run date is: 2019-11-12
+ echo 'Starting Transactions Extract...'
Starting Transactions Extract...
+ python3.7 flagship_ecom/run_transactions.py 2019-11-12
pageToken is:0 : 2019-11-12
/Users/macuser/Library/Python/3.7/lib/python/site-packages/tqdm/std.py:658: FutureWarning: The Panel class is removed from pandas. Accessing it from the top-level namespace will also be removed in the next version
from pandas import Panel
Pandas Apply: 100%|██████████████████████████████████████████████████████████████████████████████| 2737/2737 [00:00<00:00, 2971.93it/s]
++ date -I -d '2019-11-12 + 1 day'
date: illegal option -- I
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
+ d=
+ '[' '' '!=' 2019-11-14 ']'
+ echo 'Starting Data Extract...'
Starting Data Extract...
+ echo 'run date is: '
run date is:
+ echo 'Starting Transactions Extract...'
Starting Transactions Extract...
+ python3.7 flagship_ecom/run_transactions.py
Traceback (most recent call last):
File "flagship_ecom/run_transactions.py", line 17, in <module>
start_date = sys.argv[1]
IndexError: list index out of range
^Z
[8]+ Stopped bash -x ./flagship_ecom/loop_run_local.sh
bash-3.2$
I am using Mac.