1

I have two ubuntu servers and will be using a script (although I have not written it yet) on the sending server to send file abcd.txt whenever it changes using:

nc 10.10.10.4 3333 < abcd.txt

On the listening server I am using the -k option to keep it continuously listening:

nc -k -l 3333 > /home/abcd.txt

My goal is to have the file on the listening server be overwritten every time the sending server sends a file. This is not happening. Instead the entire file gets appended resulting in duplicated lines. Is there a way to fix this? I am open to options either than using netcat.

Also note, I cannot use a sort or uniq command to change the abcd.txt once it gets to the listening server due to the files being extremely large and timing constraints being imposed. (We will likely have the file on the sending end rolling every 60 seconds or so.)

1

I think the problem here is that nc is not the right solution. The listening nc never exits, so it's going to keep appending to the file.

Why not use scp or rsync? If you have sshd running on the target machine, you could use either. If you haven't, either do so, or run rsync in daemon mode.

Every time you fire up scp or rsync on the sender, the receiver will overwrite the file.

  • I'll have to look into this. I only want to run at most a single line on the listening machine, and will be writing a script to automate sending. Will scp and rsync work in that manner? – Preston Roy Jul 12 '17 at 1:34
  • If you have sshd or rsyncd running, that's just one listening process. Once running, you don't need a script or anything on the receiver - it just works. – Bob Eager Jul 12 '17 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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