#!/bin/sh

start()
{
        interface="eth1"

        while [ 1 ]
        do
                /usr/bin/tcpdump -i ${interface} -w /tmp/tcpdump.pcap > /dev/null 2>&1 &
                touch /tmp/.tcpdump
                sleep 600
                /bin/rm -rf /tmp/.tcpdump
                /bin/rm -rf /tmp/tcpdump.pcap
                killall tcpdump > /dev/null 2>&1
                break
        done
}

stop()
{
        # stop tcpdump
        /bin/rm -rf /tmp/.tcpdump
        killall tcpdump > /dev/null 2>&1
}

restart()
{
        stop
        sleep 2
        start&
}

reload()
{
        stop
        sleep 2
        start&
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        restart
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?
