Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that netcat can be used as a lightweight web-server to host a file, but I want to also have any post data saved to a separate file. Is this possible with netcat? What's the lightest way I can do something like this, preferably in os x.


share|improve this question
up vote 1 down vote accepted

Well, you can get all the html headers:-

while true
  cat some_file_to_server | nc -l 3333| head --bytes 2000 >> log_file
  date >> log_file 

This will save the first 2000 bytes of the headers and the time stamp to a log_file, then restart the server.

share|improve this answer
And the reason why you use head instead of cat is that cat will never hit an eof? – Steven Noble Mar 28 '11 at 17:22
Just to limit the length of the log file to stop it getting out of hand in case of some kind of super long header set. Everytime it finishes serving up the file it will close that instance of nc. Hence you have to have it in the loop. The other thing to watch out for is that it'll only server one connection at a time. – Decado Mar 28 '11 at 20:14

Your Answer


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.