title: Recording messages received on a port with SOCAT
body: <p>I have a server with an open port which receives between 50 and 1000 messages per second.  By message I mean that a single line of text is sent.</p>
  
  <p>Essentially we want to record these messages in a file which will be processed every hour (or x minutes).</p>
  
  <p>I have created a bash script (see below) which runs in the background and it works except when I kill the socat process (so I can take the file for processing and it can start a new file) we get part of a message, plus I am sure we are losing messages during the split second that socat is down. </p>
  
  <pre><code>DELAY="3600"
  while true
  do  
      NEXT_STOP=`date +%s --date "$DELAY second"`
      (
          while [ "$(date +%s)" -lt "$NEXT_STOP" ]
          do
              killall socat
              socat -u TCP-LISTEN:6116,reuseaddr,keepalive,rcvbuf=131071,reuseaddr OPEN:/var/ais/out_v4.txt,creat,append
          done
      ) &amp; sleep $DELAY ; killall socat
  
      mv /var/ais/out_v4.txt "/var/ais/_socat_received/"$(date +"%Y-%m-%d-%T")"__out_v4.txt"
  done
  </code></pre>
  
  <p>Is there a way to:</p>
  
  <ol>
  <li>Get socat to rotate its output file without killing the process</li>
  <li>Or can we purge the content of the file whilst SOCAT is writing to it.  e.g. cut the first 10000 lines into another file, so the output file remains a manageable size?</li>
  </ol>
  
  <p>Many thanks in advance</p>