I am struggling with a small bash shell script that should list my csv files and upload them to a external Service using curl. when i echo my command variable out to console and execute it i works fine, but when i execute it within my script it complains about a extra qouta "
my script looks like this
#!/usr/bin/bash
LOGDIR="/var/log/tyk/"
FILE_EXSTENSION_NAME="*.csv"
CURLCMD="curl -k -i -H"
PORT="9992"
ENDPOINT="/endpoint"
URL="https://localhost"
for i in `ls $LOGDIR$FILE_EXSTENSION_NAME`; do
filename=`echo $i | awk -F "/" ' { print $5 }'`
echo $filename
CMD="$CURLCMD \"filename: $filename\" -F \"data=@$LOGDIR$filename\" $URL:$PORT$ENDPOINT"
$CMD
done
When i run it i getfollowing output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--0curl: (6) Could not resolve host: 2018-October-18-10.csv"; Unknown error
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (26) couldn't open file "/var/log/tyk/2018-October-18-10.csv""
If i do a echo $CMD in my script i got
curl -k -i -H "filename: 2018-October-18-10.csv" -F "data=@/var/log/tyk/2018-October-18-10.csv" https://localhost:9992/endpoint
and that works ok
I cannot figure out what it is that i am not doing wrong
URL="https:localhost"- is that a typo? What is the exact error messasge you get? You show acurlerror message that it can't open a file, but you talk about "missing quote" errors frombash. What is it?URL=part and also tell us the exact error message you get. Maybe instead of invokingawk, you want to use thebasenametool to get the filename? Also, usels -1or betterfindto get at the list of filenames. And output$CMDbefore running it so you see what actually gets run.