I'm having a problem performing for loop on remote server, i know this can be done with one liner but i'm not sure how it works if using logical operator such as for ifs and case or while
for server in sterverA serverB serverC ; do
ssh -v $server "cd ~/MyDocuments/; bag=`find an*.txt bt*.txt se*.wav`; for file in $bag; do cp $file ${file%}.backup; done"
done
Somehow it doesn't work - it cannot find $bag
Please help
bag is a variable of the shell running on the remote server, so you need to either escape it or put the whole string in single quotes. In your case, single quotes work better because you have more parts that you wanted to escape.
Id ditch the bag variable all together and just put that command on the for loop... which eliminates a variable. you will probably need to escape the dollar sign in front of files as well.