ssh find命令和存储

时间:2016-05-07 13:25:23

标签: bash ssh find remote-access

我试图在批处理脚本中捕获查找结果 它工作正常,直到我添加另一个单词 示例外星人(作品) 外星人1(不工作)

found201=$(ssh root@192.168.1.201 find "${folder201[@]}" ! -path "*/.wdmc/*" -type f -iname "*$ffind*" | sort)

如果我在终端中运行

found201=$(ssh root@192.168.1.201 'find /shares/Public/ /shares/Videos/ -type f -iname "*alien 1*"' | sort)

使用'find .....'它可以工作,但没有什么是加上它不使用字符串/数组

当我添加''到脚本得到错误的替换(假设它现在被视为字符串而不是命令)

我需要使用find,因为我需要以设定的方式删除文件等

如何添加''来查找和使用字符串/数组

正常运行得到这个

++ ssh root@192.168.1.201 find /shares/Public/ /shares/Videos/ '' '!' -path '*/.wdmc/*' -type f -iname '*alien 1*'
++ sort
find: unrecognized: 1*

2 个答案:

答案 0 :(得分:0)

尝试这样,将整个find命令括在双引号中,并在内部使用单引号:

found201=$(ssh root@192.168.1.201 "find ${folder201[@]} ! -path '*/.wdmc/*' -type f -iname '*$ffind*'" | sort)

但有一点需要注意: 这不适用于${folder201[@]}中包含空格的文件夹。

答案 1 :(得分:-1)

认为我已经对它进行了分类

found201=$(ssh root@192.168.1.201 "find ${folder201[@]} ! -path '*/.wdmc/*' -type f -iname '*$ffind*'" | sort)

将'$ {folder201 [@]}'更改为$ {folder201 [@]}(删除单引号)