linux - 在多个服务器的 Linux 中搜索多个目录中的字符串

标签 linux string shell search scripting

我想在 Linux 机器的所有目录中以递归方式在根级别搜索字符串。我知道我可以使用 grep,但我的要求是在脚本中的多个服务器中找到该字符串。

我只是在尝试这个。谁能进一步帮助

for host in host1 host2 host3
do
    ssh "$host" grep -R "test" / 2>/dev/null
done

最佳答案

似乎尝试在所有服务器上找到给定的文件,这可以通过以下方式实现

for host in host1 host2 host3
do
    ssh "$host" find / -name "test"  2>/dev/null
done

编辑 1:

为了在多个主机的文件中找到给定的字符串,我们可以尝试

对于 host1 host2 host3 中的主机 做 ssh "$host"查找/-type f | grep“测试”2>/dev/null 完成

关于linux - 在多个服务器的 Linux 中搜索多个目录中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21513356/

相关文章:

linux - 我可以使用 wget 从 linux 终端下载多个文件吗

c++ - ofstream 输出字符串/字符而不是 double

linux - Shell多日志监控与关联

mysql - Shell - 使用包含双引号的字符串变量

linux - 放置自定义可执行文件或脚本的 Unix 标准目录?

c - Linux 内核模块 : printk message not where I expect to be in the buffer log

linux - 段错误 debian 8 golang

linux - 删除所有在 linux 中有 'nth' 逗号的东西

python - 用给定字符串替换字符串中的字符

string - Scala 检查元素是否存在于列表中