I am new to linux and i am writing a bash script... In the script, I have 2 variables(inside the varibles contents are there). I am trying to pass these 2 varibales in a same for loop and perform some actions.
But when i pass 2 varibles in a same for loop, am getting error. In the below code. to make it ease I am passing two paramerters but in actual it will vary. I am getting output of these varibales from a command
Below is my code:
FILES="2019_06/
2019_07/"
FILESIZE="100
200"
for file in `cat $FILES`; for filesize in `cat $FILESIZE`
do
do
if [ -n "$file" ] && if [ -n "$filesize" ]
then
echo $file
curl -i -XPOST "http://localhost:8086/write?db=S3check&precision=s" --data-binary 'ecmwftrack,bucketpath=ecmwf-archive/'$file' size=$filesize'
fi
done
done
Could any one pls help me to pass 2 arguments in the for loop at the same time.
Argument should pass like in the for loop
FILES=2019_06 FILESIZE=100
FILES=2019_07 FILESIZE=200
Below is the error message
Kindly help!
Below is my output
Below is my curl coomand
echo curl -i -XPOST "http://localhost:xxxx/write?db=S3check&precision=s" --data-binary 'ecmwftrack,bucketpath=ecmwf-archive/'$files' size='$filesizes''
#!/bin/bash -x
# You said variables get their values from commands, so here
# are stand-ins for those commands:
command_to_get_files(){
aws s3 ls "s3://ui-dl-weather-ecmwf-ireland/ecmwf-archive/"| awk '{print $2}' >>"$FILES"
}
command_to_get_filesizes(){
for file in `cat $FILES`
do
if [ -n "$file" ]
then
# echo $file
s3cmd du -r s3://ui-dl-weather-ecmwf-ireland/ecmwf-archive/$file | awk '{print $1}'>>"$FILESIZE"
fi
done
}
# I assume the values returned from the commands are whitespace delimited
# Therefore it is easy to use command substitution and transform the output
# of the commands into arrays:
files=( $(command_to_get_files) )
filesizes=( $(command_to_get_filesizes) )
do
after the firstfor
– pLumo May 04 '20 at 05:43do
after the firstfor
– pLumo May 04 '20 at 06:01