Objective
I'm trying to create a loop that will use my logins, select an account based on column 1
and then select the platform based on column 2
of input.csv
. I have assigned each column to it's own variable in the hopes that it will loop through each row together and pull the reports i need, instead of me having to make a super long script of copy and paste.
input.csv
729352,7
355543,7
461432,7
Current Code
#! bin/sh
set -eu
value1=$(awk -F"," -v OFS=',' '{ print $1 }' input.csv)
value2=$(awk -F"," -v OFS=',' '{ print $2 }' input.csv)
rm -f cookiejar
curl /dev/null -s -S -L -f -c cookiejar 'https://url/auth/authenticate' -d name=usr -d passwd='pwrd'
while IFS="," read -r value1 value2 remainder
do
curl -o /dev/null -s -S -L -f -b cookiejar -c cookiejar 'https://url/auth/adminaccounts' -d account=$value1
curl -s -S -L -f -O -J -b cookiejar -c cookiejar "https://url/report/ajax-by-tag2?platform_id[]=$value2&id1=&id2=&id3=&id4=&id5=&id11=&id12=&id13=&date=2019-11-25&date_start=&date_end=&website=&zfTablePage=1&zfTableColumn=&zfTableOrder=desc&zfTableQuickSearch=&zfTableItemPerPage=100&zfTableDataTablesMaxRows=1&zfDetails=false&by_viewability=imps_givt&device_id[]=all&tag_type_id[]=all&support_id[]=all&zfTableItemPerPage=10000&zfTableExport=xlsx"
done < "input.csv"
Current Error
+curl -o /dev/null -s -S -L -f -b cookiejar -c cookiejar https://urlauth/adminaccounts -d account=729352
&id1=&id2=&id3=&id4=&id5=&id11=&id12=&id13=&date=2019-11-25&date_start=&date_end=&website=&zfTablePage=1&zfTableColumn=&zfTableOrder=desc&zfTableQuickSearch=&zfTableItemPerPage=100&zfTableDataTablesMaxRows=1&zfDetails=false&by_viewability=imps_givt&device_id[]=all&tag_type_id[]=all&support_id[]=all&zfTableItemPerPage=10000&zfTableExport=xlsx
curl: (3) Illegal characters found in URL
What I have tried
- I have replaced variable 2 in the url with the value "7" and can confirm that it loops through column 1 pulling each file.
- I can confirm that variable 2 populates "7" correctly if I changed it with variable 1 (though it obviously doesn't download anything as it's not an account).
- I've tried doing various different quote options around the url but every time it spits out the error above.
- I've tried to put brackets around the variable
{$value2}
which I found worked when I used variables in the url previously. - Reviewing online, there is a lot of talk about the error being caused by different parts of the url, but I know the issue lies with the variable as it works without it. Can someone tell me what I seem to be missing to get this to work correctly?