Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ack over ssh not work?

Tags:

grep

bash

ssh

ack

I've got a simple bash script to remove some folders on a remote server over 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 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 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?

like image 607
kramer65 Avatar asked Nov 27 '25 18:11

kramer65


1 Answers

Could be ack behaves differently when it is run in a terminal. Try using the -t argument

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. 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.

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. See http://github.com/beyondgrep/ack2/issues/659

like image 69
nos Avatar answered Nov 29 '25 14:11

nos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!