我试图运行以下命令:
ssh -A -t -i ~/.ssh/DevKP.pem -o StrictHostKeyChecking=no root@MyServer "for file in \`ls /root/spark/work/ \`; do echo 'file - ' $file; done"
输出结果为:
file -
file -
Connection to MyServer closed.
当我在远程服务器上运行命令时:
for file in `ls /root/spark/work/ `; do echo 'file - ' $file; done
我得到了输出:
file - test1.txt
file - test2.txt
如何让ti在本地服务器上运行?它似乎得到了正确的文件(因为有两个sysouts)
任何人都有任何想法?
感谢
答案 0 :(得分:1)
您需要转义$
中的$file
以确保远程shell解释它而不是本地。您还应该将ls /root/..
简化为for file in /root/../*
:
ssh root@MyServer "for file in /root/spark/work/* ; do echo 'file - ' \$file; done"