Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Feb 22 '13 at 6:09

This question came from our site for professional and enthusiast programmers.

2 Answers 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

share|improve this answer
    
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 '13 at 16:53
    
That's because tail -f doesn't exit; it follows the file forever, until you explicitly kill it. –  chepner Feb 23 '13 at 0:38

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.

share|improve this answer
    
Very interesting command! It works with your example, but not with zfs for some reason. –  Sandra Feb 22 '13 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.