Help, ssh is eating up all my standard input!

If you're running ssh inside a shell script that's reading from standard input (stdin), beware that the ssh execution will drain stdin unless you use the -n option.

For example, take this loop:

while read host; do
   ssh "$host" hostname
done < /path/to/list-of-hosts

This will only loop once even if the file has multiple lines, since ssh is reading stdin attached to the whole loop and forwards it to the stdin of the "hostname" command executed on the remote host (which happily discards it, not reading from stdin at all).


diff remote files interactively with vim and ssh

Oh, this comes in handy:

vimdiff /path/to/file scp://remotehost//path/to/file

Damn, how many features do I actually know of vim? (thanks, Mika for pointing this out, there's even a blog post about it)

Subscribe to RSS - ssh