curl with variables on bash script
Try something like this:
amz_t=$(cat amazon-token.txt)
flx_id=$(cat flex-id.txt)
ses_t=$(cat session-token.txt)
UA='iOS/10.2.2 (iPhone Darwin) Model/iPhone Platform/iPhone6,1 RabbitiOS/2.0.141'
URL='https://flex-capacity-na.amazon.com/GetOffersForProvider?serviceAreaIds=122'
curl -s -H 'Host: flex-capacity-na.amazon.com' \
-H "Cookie: session-token=$ses_t" \
-H "x-amz-access-token: $amz_t" \
-H "x-flex-instance-id: $flx_id" \
-H 'Accept: */*' \
-H "User-Agent: $UA" \
-H 'Accept-Language: en-us' \
--compressed "$URL" >> output.txt
Use single-quotes for fixed strings (i.e. without any variables in them) and double-quotes for strings that need variable interpolation to take place.
You can't use single quotes on your variables. This will cause bash to not interpret the $
special character. You can use double quotes instead.
http://tldp.org/LDP/abs/html/quoting.html
EDIT
I realize now you are closing all your single quotes before and re-opening them after your variables but the variables are still probably being read incorrectly because they aren't quoted. I'm not sure you even need to single quote everything in this command but if you do you can still put your double quotes in like below:
Change your line:
curl -s -H 'Host: flex-capacity-na.amazon.com' -H 'Cookie: session-token='$ses_t'' -H 'x-amz-access-token: '$amz_t'' -H 'x-flex-instance-id: '$flx_id'' -H 'Accept: */*' -H 'User-Agent: iOS/10.2.2 (iPhone Darwin) Model/iPhone Platform/iPhone6,1 RabbitiOS/2.0.141' -H 'Accept-Language: en-us' --compressed 'https://flex-capacity-na.amazon.com/GetOffersForProvider?serviceAreaIds=122' >> output.txt
To:
curl -s -H 'Host: flex-capacity-na.amazon.com' -H 'Cookie: session-token='"$ses_t" -H 'x-amz-access-token: '"$amz_t" -H 'x-flex-instance-id: '"$flx_id" -H 'Accept: */*' -H 'User-Agent: iOS/10.2.2 (iPhone Darwin) Model/iPhone Platform/iPhone6,1 RabbitiOS/2.0.141' -H 'Accept-Language: en-us' --compressed 'https://flex-capacity-na.amazon.com/GetOffersForProvider?serviceAreaIds=122' >> output.txt
But I think this would work too:
curl -s -H 'Host: flex-capacity-na.amazon.com' -H "Cookie: session-token=$ses_t" -H "x-amz-access-token: $amz_t" -H "x-flex-instance-id: $flx_id" -H 'Accept: */*' -H 'User-Agent: iOS/10.2.2 (iPhone Darwin) Model/iPhone Platform/iPhone6,1 RabbitiOS/2.0.141' -H 'Accept-Language: en-us' --compressed 'https://flex-capacity-na.amazon.com/GetOffersForProvider?serviceAreaIds=122' >> output.txt