Mike
Mike

Reputation: 60839

How can I tee the output of an ssh script?

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?

Upvotes: 2

Views: 1666

Answers (1)

anubhava
anubhava

Reputation: 786091

You can use:

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

Upvotes: 3

Related Questions