0

I want to execute local script on remote machine with additional file descriptors.

#!/bin/bash
echo "first log"
echo "second log" >&3

I try to run it that way:

ssh remote_host 'bash -s' < test.sh >first.log 3>second.log

Only my first log is populated. For second it gives "Bad file descriptor" error.

Алдар
  • 175
  • 8
  • Well... what the file descriptor 3 is supposed to be? `echo` command opens by default 3 files descriptors (like all the commands by default): 0 (stdin), 1 (stdout) and 2 (stderr). You want to redirect the file descriptor 3, which do not exist, hence the descriptive error: `Bad file descriptor` – Poshi Jul 09 '18 at 12:06
  • 1
    ssh only connects local fd0 to remote fd0, local fd1 to remote fd1, and local fd2 to remote fd2. I don't think there is any way to do what you ask. [Similar question](https://unix.stackexchange.com/questions/226638/ssh-provide-additional-pipe-fds-in-addition-to-stdin-stdout-stderr) –  Jul 09 '18 at 12:11
  • Poshi, the script works successfully on local execution. Wumpus, the solution provided in similar threat it too hard. It would be much easier to "echo" 3rd descriptor into log file directly from remote host and then copy it to local. – Алдар Jul 10 '18 at 01:50

0 Answers0