title: Regenerating the output after deleting it in periodic way in tcpdump
body: <p>I need to monitoring the network using a tcpdump. However I need to delete its output(train.txt) every 5 seconds from its folder manually. I am looking for a approach to regenerate the output in a bash file. In other words, as I delete the output of tcpdump, it generates a new output with new contents. Here is my code: </p>
  
  <pre><code>#!/bin/bash
  FILE="/media/sf_sharedsaeed/train.txt"
  #Change the eth for each host first
  tcpdump -i h1-eth0 -l -e -n 'port 80' &amp; &gt; /media/sf_sharedsaeed/train.txt
  while true
  do
  if [ -f $FILE ]; then
     echo "******************* tcpdump do its job well******************* "
  else
      #now interrupt the process. get its PID:
      pid=$(ps -e | pgrep tcpdump)
      echo $pid
  
      kill -2 $pid
      echo "File $FILE does not exist. tcpdump make it again."
      tcpdump -i h1-eth0 -l -e -n  &gt; /media/sf_sharedsaeed/train.txt
  
  fi
  
  done
  </code></pre>
  
  <p>The problem is that, as the output deleted, no new output file generated anymore. Please help me. </p>
  
  <p>Update:
  I used this code to delete the file content instead of deleting the file: (using cat /dev/null > $FILE)</p>
  
  <pre><code>#!/bin/bash
  FILE="train.txt"
  second=5
  
  while true
  do
  awk '{print $10" "$12}' $FILE | sort | uniq -c &gt; output.txt
  echo "New output.txt generated."
  #truncate -s 0 $FILE
  cat /dev/null &gt; $FILE
  echo "wait for 5 seconds ..."
  sleep $second
  done
  </code></pre>
  
  <p>As I used it, the output(train.txt) is not fill completely. Some data will missed! </p>