How can I tee the output of an ssh script?

1.5k views Asked by At

I want to capture the output of a shell SSH script to a file and have it on stdout at the same. I know I can use tee but it doesn't seem to be working as I expect in this case.

Example,

#!/bin/sh

ssh user@host | tee /tmp/a << EOF
echo hi
EOF

I expect hi to be in /tmp/a, instead it looks like ssh waits forever for input.

If I replace ssh with cat it works as I expect

#!/bin/sh

cat | tee /tmp/a << EOF
hi
EOF

Output: hi

$ cat /tmp/a
hi

What's the difference between ssh and cat here?

1

There are 1 answers

0
anubhava On BEST ANSWER

You can use:

ssh user@host << EOF | tee /tmp/a
echo hi
EOF