There's something funny with tail -f and grep -o combination when running over ssh.

So on local server, if you do

tail -f /path/myfile.log |grep -o keyword

It grep just fine. But if you run it on remote server....

ssh user@server 'tail -f /path/myfile.log |grep -o keyword'

doesn't work. Nothing comes back as if it was redirected to /dev/null!

But if you remove -f from tail or -o from grep, work just fine... weird :-/

Of course I could create a script on the remote server and just run the script! But that's not quite suitable for my situation.

  • Different flavors of linux? different options set in system config files? there could be many reasons.... – Tyson Dec 31 '14 at 15:41
  • How about privileges to execute in remote server?. – vembutech Dec 31 '14 at 16:14
  • Here is a post that should be helpful. unix.stackexchange.com/questions/21920/… – Russ Huguley Dec 31 '14 at 16:23

Apparantly SSH doesn't do line buffering without a terminal.

ssh -t ensures that pseudo terminal created and therefore programs that uses line buffering works. This also ensures your login profile is executed so that you get correct environment setup for the user too. Also screen based commands like vim works only if you use -t flag.

This blog has some nice tips btw http://lugatgt.org/2009/10/28/ssh-tips-and-tricks-2/

  • Technically, it's grep which is buffering output by blocks instead of by lines, because its output isn't to a TTY. – Kenster Jan 5 '15 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.