Search 如何远程使用shell脚本搜索目录模式
我需要使用scp更新另一台服务器上的一些目录。它类似于Search 如何远程使用shell脚本搜索目录模式,search,shell,design-patterns,scp,Search,Shell,Design Patterns,Scp,我需要使用scp更新另一台服务器上的一些目录。它类似于 for i in /usr/some/???/unknown/dir do cp /usr/some/file $i done 那么,当目标目录位于其他服务器上时,如何进行搜索呢 谢谢如果您在远程服务器上有shell访问权限,请远程创建目录列表(使用find、ls或shell脚本中使用的任何工具),然后将其复制回您要从中复制的系统。然后你可以用 for d in file_of_remote_dirs; do scp /usr/s
for i in /usr/some/???/unknown/dir
do
cp /usr/some/file $i
done
那么,当目标目录位于其他服务器上时,如何进行搜索呢
谢谢如果您在远程服务器上有shell访问权限,请远程创建目录列表(使用find、ls或shell脚本中使用的任何工具),然后将其复制回您要从中复制的系统。然后你可以用
for d in file_of_remote_dirs; do
scp /usr/some/file remote_machine:d;
done
我想,这个发现正是您想要的…每个人都会忘记处理文件名中的空格:p 要重用LB的示例,请执行以下操作:
OLD_IFS=$IFS
IFS=$\'n'
for i in `ssh user@otherhost find /usr/some -type d -name dir`
do
scp user@otherhost:"/usr/some/dir/$i" .
done
IFS=$OLD_IFS
这将在输出的每一行而不是每一个单词上循环(引用$i)。是的,你说得对。。。我总是忘记。。。但我总是说文件名中的空格是邪恶的…:-)
for i in `ssh user@otherhost find /usr/some -type d -name dir`
do
scp user@otherhost:/usr/some/dir/$i .
done
OLD_IFS=$IFS
IFS=$\'n'
for i in `ssh user@otherhost find /usr/some -type d -name dir`
do
scp user@otherhost:"/usr/some/dir/$i" .
done
IFS=$OLD_IFS