Answer the question
In order to leave comments, you need to log in
How to make netcat save data to a file?
There is a certain service that periodically sends packets to the server on a specific port. I want to hang netcat on it so that all incoming packets are saved to a given file in the background.
If run
nc -k -lp 8080 >> data.txt &
Then it takes one packet and exits.
If you run it like this:
Then the process receives and writes one packet, displays something like:
while true; do nc -k -lp 8080 >> data.txt; done &
[2]+ Stopped while true; do
nc -k -lp 8080 >> data.txt;
done
Answer the question
In order to leave comments, you need to log in
Decided on my own. This code works correctly, plus, as a bonus, timestamps are written in the log along with the package dump:
while true; do (date; nc -k -lp 8080 2>&1 | sed 's/\r//g') | xargs >> environ.txt; done &
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question