LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 971|回复: 3

ssh执行这几个命令组合无效?

[复制链接]
发表于 2006-3-8 10:16:35 | 显示全部楼层 |阅读模式
我执行下面的命令没有结果:
local# ssh USER@HOST "find DIR -type f | grep FILENAME | while read line; do echo $line; done"

但这样却可以:
remote# find DIR -type f | grep FILENAME | while read line; do echo $line; done

我最终是想要实现这样的目标:
ssh USER@HOST "find DIR -type f | grep FILENAME | while read line; do grep -h 'SOMETHING' $line; done"

请问这是什么原因?有没有好的解决办法?

谢谢
发表于 2006-3-8 13:36:49 | 显示全部楼层
I think its becase "|" will fork a subshell on remote and can't feek the output to the current ssh pseudo tunnel. You can try something like:

  1. ssh user@host 'while read line;do echo $line;done< <(find DIR -type f -name "something")'
复制代码
. This will make sure no subshell forked and everything is executed and outputed in current shell.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-8 14:27:06 | 显示全部楼层
还是不行,在本地执行可以,在远端就不行(全部变成了空行)。

而且我这里最好能用正则表达式,因为 filename 包含 Time,用 grep 可以使用 "prefix.*date" 的形式,但用 find -name 则不能使用 "prefix.*date" 或 "prefix*date" 的形式。

不过< <(find DIR -type f -name "something")' 的用法我还是第一次看到,先谢过了:thank
回复 支持 反对

使用道具 举报

发表于 2006-3-8 15:16:58 | 显示全部楼层
是吗?我这里是可以的回显回来的。按理应该是可以的。至于find的regex匹配,find有option, -regex。看看man
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表