1

I am having this interesting problem, where I would like to start this command

nc -l 8023 | zfs receive tank3/pro1

on a remote host 10.10.10.11.

If I run

ssh -n 10.10.10.11 'nohup nc -l 8023 | zfs receive tank3/pro1 &'

from inside a script, then it doesn't continue in the script, because zfs it is waiting for STDIN.

If I redirect STDIN, STDOUT, STDERR

ssh -n 10.10.10.11 'nohup nc -l 8023 | zfs receive tank3/pro1 &> /dev/null < /dev/null &'

then the script continues, but redirecting STDIN destroys the zfs command.

Question

Can screen be used to solve this?

Or other ideas?

3 Answers 3

2

You can try following example:

ssh -t root@server1 screen "tail -f /var/log/messages"

-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful

2
  • It starts tail on the remote host in screen, but doesn't give me the shell back on the local host, so my script can continue.
    – Sandra
    Feb 22, 2013 at 16:53
  • That's because tail -f doesn't exit; it follows the file forever, until you explicitly kill it.
    – chepner
    Feb 23, 2013 at 0:38
0

I dont have ZFS, but I made a simple script to mimic reading stdin. Seems to work for me

~/sand/readme.sh:

#!/bin/sh
while read X
do
   echo $X
done

And then:

ssh localhost "nc -l 8023 | ~/sand/readme.sh &\\disown"

Or with single quotes:

ssh localhost 'nc -l 8023 | ~/sand/readme.sh &\disown'

\ separates multiple remote ssh commands, or at least seems to behave this way for me :). disown will allow you to break from a backgrounded job. I use this whenever I run a long command and realize only after I should have done it in a screen. CTRL+Z; bg; disown if you ever find yourselves in that scenario. You can logout of SSH and it will continue to run in background.

1
  • Very interesting command! It works with your example, but not with zfs for some reason.
    – Sandra
    Feb 22, 2013 at 16:54
0

You can indeed use screen for this, with -d -m to start in detached mode:

ssh 10.10.10.11 screen -d -m 'nc -l 8023 | zfs receive tank3/pro1'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .