6

I have a script where I would like to start nc in listening mode on 10.10.10.11, but I would like to do it from 10.10.10.10, where I have this script

ssh -n 10.10.10.11 nc -l 8023 | mbuffer -s 128k -m 1G | zfs receive $zfsPath
zfs send $newestSnap | mbuffer -s 128k -m 1G | nc -w 60 10.10.10.11 8023

The problem is, that if I execute the script from 10.10.10.10 then it won't continue after the first line have been executed, because nc is now waiting/listening for a connection on port 8023.

Question

I would like to execute the above from 10.10.10.10, but how do I get it to continue after the first line?

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
Sandra
  • 10,303
  • 38
  • 112
  • 165
  • You can start things in the background by using `&` behind the command. I am not sure of the precise syntax, but if you put all in one [shell]command and add & it should work. – Hennes Feb 13 '13 at 16:25

1 Answers1

6

Try

ssh -n 10.10.10.11 "nc -l 8023 | mbuffer -s 128k -m 1G | zfs receive $zfsPath &"
zfs send $newestSnap | mbuffer -s 128k -m 1G | nc -w 60 10.10.10.11 8023

This runs the command and puts it in the background allowing control to pass on to the next line.

I don't have a zfs system to hand so tested it with

ssh -n remote.tld  "nc -l 8023 | wc -l  >/tmp/test &"
ls | nc -w 60 remote.tld 8023

and the correct output appeared in the remote /tmp/test file.

user9517
  • 115,471
  • 20
  • 215
  • 297