0

Shell script allow multiple file descriptors (up to 9 for POSIX compliance, but even more for bash):

$ install -m 755 /dev/stdin /tmp/test <<\EOF
#!/bin/sh

echo hi1 >&1
echo hi2 >&2
echo hi3 >&3
echo hi4 >&4
EOF
$ /tmp/test 1> /tmp/1 2> /tmp/2 3> /tmp/3 4> /tmp/4
$ cat /tmp/1
hi1
$ cat /tmp/2
hi2
$ cat /tmp/3
hi3
$ cat /tmp/4
hi4

I want to achieve the same behaviour over SSH, but what happens is:

$ ssh user@remote_machine /tmp/test 1> /tmp/1 2> /tmp/2 3> /tmp/3 4> /tmp/4
$ cat /tmp/1
hi1
$ cat /tmp/2
hi2
/tmp/test: 5: /tmp/test: 3: Bad file descriptor
/tmp/test: 6: /tmp/test: 4: Bad file descriptor
$ cat /tmp/3
$ cat /tmp/4

Is it possible to have multiples output pipes over SSH other than stdout and stderr?

It is important to note I am not looking for port forwarding, since I will have network issues.

1 Answer 1

1

No, that's not doable. The ssh client explicitly closes every open file descriptor larger than 2:

/*
 * Discard other fds that are hanging around. These can cause problem
 * with backgrounded ssh processes started by ControlPersist.
 */
closefrom(STDERR_FILENO + 1);

This is almost the first thing that happens when the client starts (see main() in the source code for OpenSSH 8.0 available here).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.