#!/bin/bash

starthour=$(date "+%H")
echo "Datetime is `date "+%y-%m-%d %H:%M:%S"`"
tcpdump -nlASX -s 0 -vvv -i eth3 host 192.2.0.55 -w `date "+%Y-%m-%d--%H-%M-%S--carriername--turnkname"`.pcap > /dev/null  2>&1 &
dumppid=$!
echo "dumppid is $dumppid"

while true;
do

  nowhour=$(date +"%H")
  if [ $nowhour -ne $starthour ]
  then
    starthour=$(date "+%H")
    echo "Datetime is `date "+%y-%m-%d %H:%M:%S"`"
    kill $dumppid
    find . -maxdepth 1 -mtime 4 -name "*.pcap" -exec rm {} \;
    tcpdump -nlASX -s 0 -vvv -i eth3 host 192.2.0.55 -w `date "+%Y-%m-%d--%H-%M-%S--carriername--turnkname"`.pcap > /dev/null  2>&1 &
    dumppid=$!
    echo "dumppid is $dumppid"
  fi
  
  sleep 300

done
