Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Thanks

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Well, you can get all the html headers:-

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

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
add comment

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.