2015-01-13

tcpdump를 이용한 시간별 capture 파일 생성

vi capture.sh
#!/bin/bash

if [ "$1" != "" ] && [ "$2" != "" ]; then
   TRUE=1
   while [ $TRUE ]
   do
      r_date=`date +%Y%m%d%H%M`
      let d_date=$(($r_date+$2))
      echo $d_date
      tcpdump -nn -i $1 -w $r_date.pcap & 
      ex_tcpdump=`echo $!`
      while [ $TRUE ]
      do
         tmp_date=`date +%Y%m%d%H%M` 
         if [ $d_date -le $tmp_date ]; 
         then
            kill $ex_tcpdump 
            break
         else
            continue
            sleep 1
         fi
      done
   done
   break
else 
   echo $0 ': version 0.0.1a by stevebooks.com'
   echo 'Usage:' $0 '<interface> <dalay(per minitues)>'
   echo '=============================================='
   echo 'e.g.' $0 'eth0 1'
fi
chmod 755 capture.sh

아래와 같이 script를 실행하면 됩니다. (eth0 interface를 이용하여 2분단위로 capture파일 생성)
./capture.sh eth0 2

댓글 없음:

댓글 쓰기