简体   繁体   English

在SSH中按名称查找和替换文件或文件夹

[英]Find And Replace Files Or Folders By Name In SSH

I have several websites on my hosting account. 我的托管帐户上有几个网站。 Due to the security layers in place I cannot use symbolic linking, or include from from account to account. 由于安全层的到位,我不能使用符号链接,也不能在每个帐户之间添加符号链接。 However I am a set of scripts that are going to be the same account several accounts. 但是我是一组脚本,这些脚本将是同一个帐户或多个帐户。

Rather than uploading these scripts to each individual ftp account every time a change is made I want to have a simple bash script that will do it for me. 与其每次进行更改,都不要将这些脚本上载到每个单独的ftp帐户,而是要有一个简单的bash脚本来为我做。

So what I want to do via SSH is to search my hosting server for a specific directory by name, for example "ThisUniqueFolder", then upload and replace all the files within that directory with the updated versions of the files that are stored on my local server. 因此,我要通过SSH进行的操作是按名称搜索主机服务器中的特定目录,例如“ ThisUniqueFolder”,然后上载该目录中的所有文件,并将其替换为本地存储文件的更新版本。服务器。

Keeping in mind that this directory "ThisUniqueFolder" will exist in several different locations throughout the hosting server. 请记住,此目录“ ThisUniqueFolder”将存在于整个主机服务器的几个不同位置。

You can use ssh to find all ThisuniqueFolder , then use rsync to update them all. 您可以使用ssh查找所有ThisuniqueFolder ,然后使用rsync更新它们。

Use ssh 's -i identity_file to avoid password for user at remote_host . 使用ssh-i identity_file可以避免remote_host user使用密码。

#!/bin/bash
for f in `ssh -i /path/to/identity_file user@remote_host 'find /remote/search/directory -name "ThisUniqueFolder" -type d'`
do 
    rsync -avu -e 'ssh -i /path/to/identity_file' ThisUniqueFolder/ user@remote_host:$f
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM