#!/bin/bash

starthour=$(date "+%H")
echo "Datetime is `date "+%y-%m-%d %H:%M:%S"`"

tcpdump -nlASX -s 0 -i eth0 -G 1800 -w ./%Y-%m-%d--%H-%M-%S--sip-trunk.pcap host 192.2.0.55 and udp > /dev/null 2>&1 &

while true;
do

  nowhour=$(date +"%H")
  if [ $nowhour -ne $starthour ]
  then
    starthour=$(date "+%H")
    find ./ -maxdepth 1 -mtime +4 -name "*.pcap" -exec rm {} \;
  fi
 
  sleep 1800

done
