1

I have an awk script in .bashrc that reads characters and modifies some keywords. It works perfectly when I pipe tail -f and other basic commands through it, but I have a problem when I pipe ssh through it. Everything works fine as expected except I cannot see anything I type on terminal until I press return:

~# ssh admin@localhost -p 5200 | my-script

admin@localhost's password: 

admin connected from 127.0.0.1 using ssh on home

admin@ssh-server> exit   ***<- I don't see this line (including the prompt) at all on terminal until I type my command (exit) and press Enter***

Connection to localhost closed.

I think I understand why it's behaving like that but don't know how to fix it. I think the interactive commands to ssh are not sent through pipe until EOL is returned. I have tried everything I found searching from unbuffer/stdbuf to tee/script and playing with various redirection commands but all without luck.

Note: I'm actually ok that the strings are passed to my-script after EOL, I just need to be able to see what I'm typing i.e. need terminal stdin to echo as usual.

  • it won't echo if you pipe it away. Use a tee to pipe it into the file and then into the script. Or make your script to do that job. – Jakuje Aug 15 '17 at 10:01
  • @Jakuje - I assume you meant 'ssh example.com | tee file | my-script' .... I still see same behavior. Can't see what I'm typing until hit return (no stdin echo by tty kernel). – lamp Aug 15 '17 at 18:00
1

I am able to do the following:

$ ssh user@example.com | tee output
Last login: Tue Aug 15 03:06:11 2017 from 127.1.2.3
$ ls /
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
$ logout
Shared connection to example.com closed.
$ cat output
Last login: Tue Aug 15 03:06:11 2017 from 127.1.2.3
$ ls /
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
$ logout

I see the prompt, my input, and everything else when sshed into the remote host as normal.

  • you're teeing to a file named 'output'... that's not what I'm doing. I'm piping to an awk script shown as 'my-script' – lamp Aug 15 '17 at 4:08
  • How about | tee >(my-script)? – András Korn Aug 15 '17 at 10:42
  • @AndrásKorn - that works partially. I get duplicate output on terminal, one from ssh and one from my-script. I need the interactive ssh output to be processed by my-script first and then printed on terminal. – lamp Aug 15 '17 at 18:11
  • You could try to make stdin and stdout unbuffered using stdbuf -i0 -o0, but something your script does may still insist on reading an entire line before outputting anything. – András Korn Aug 15 '17 at 18:45
  • @AndrásKorn - I had tried stdbuf before without luck. Also I'm totally ok with my script reading an entire line before outputting, the problem is I can't see what is being typed inside ssh session i.e terminal doesn't echo stdin until eol is returned. – lamp Aug 15 '17 at 21:43

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.