简体   繁体   English

为什么 ack over ssh 不起作用?

[英]Why does ack over ssh not work?

I've got a simple bash script to remove some folders on a remote server over ssh.我有一个简单的 bash 脚本来通过 ssh 删除远程服务器上的一些文件夹。 It basically does this:它基本上是这样做的:

THE_HOST=12.34.56.78
ssh me@$THE_HOST "rm /the/file/path/thefile.zip"

This works perfectly well.这非常有效。 Before I do this I often search the contents of the files in a folder for a string using ack :在我这样做之前,我经常使用ack在文件夹中的文件内容中搜索字符串:

ack thestring /the/folder/path/

This works perfect when I ssh into the server and run it, but when I use it in one command it doesn't work:当我 ssh 进入服务器并运行它时,这很完美,但是当我在一个命令中使用它时,它不起作用:

ssh me@$THE_HOST "ack thestring /the/folder/path/"

This seems to freeze or run forever: I get no output and the command never ends.这似乎永远冻结或运行:我没有输出并且命令永远不会结束。 Does anybody know why this doesn't work for ack?有人知道为什么这对 ack 不起作用吗?

Could be ack behaves differently when it is run in a terminal.当 ack 在终端中运行时,它的行为可能会有所不同。 Try using the -t argument尝试使用 -t 参数

ssh -t me@$THE_HOST "ack thestring /the/folder/path/"

When ack detects that stdin is not a terminal(a tty device), it will attempt to read the text to search in from stdin instead of the given file/folder.当 ack 检测到 stdin 不是终端(tty 设备)时,它将尝试从 stdin 而不是给定的文件/文件夹读取文本以进行搜索。 That's what happens when you run it through ssh, stdin will be connected to the ssh connection, which does not look like a terminal(tty) to ack.这就是当您通过 ssh 运行它时会发生的情况,stdin 将连接到 ssh 连接,这看起来不像终端(tty)来确认。

The -t argument to ssh instead allocates a tty and connects it to stdin/out of the program you run, ack will then think it runs in a terminal and instead use the file/folder argument for searching. ssh的 -t 参数会分配一个 tty 并将其连接到您运行的程序的 stdin/out,然后 ack 会认为它在终端中运行,而是使用文件/文件夹参数进行搜索。 See http://github.com/beyondgrep/ack2/issues/659http://github.com/beyondgrep/ack2/issues/659

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

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