Each time, when I manually run tcpdump
, I have to use Ctrl+C to stop it. Now I want to schedule my tcpdump
with cronjob and I onl
You can use
watch tcpdump -i eth0 'port 8080' -w myfile
This will run every 2 seconds.
You could do it like this:
tcpdump -i eth0 'port 8080' -w myfile &
pid=$!
sleep 1.5h
kill $pid
you could use timeout
timeout 5400 tcpdump -i eth0 'port 8080' -w myfile
The approach that worked best for me on Ubuntu 14.04
sudo -i
crontab -e
and then add the line
30 17 * * * /usr/sbin/tcpdump -G 12600 -W 1 -s 3000 -w /home/ubuntu/capture-file.pcap port 5060 or portrange 10000-35000
Notes
You can combine -G {sec}
(rotate dump files every x seconds) and -W {count}
(limit # of dump files) to get what you want:
tcpdump -G 15 -W 1 -w myfile -i eth0 'port 8080'
would run for 15 seconds and then stop. Turn 1.5 hours into seconds and it should work.