Lately I needed to run tcpdump
on several servers for a given time, and then download the pcap
fiels, all in a programmatic way.
So I got to know the useful timeout
command, simple and straight-forward.
timeout 120s tcpdump -s 0 -A dst port 80
Remember that if you are not running as root
and using sudo
, you will need to put sudo
before the timeout
command, so it can actually send the SIGTERM
without getting Permission denied
.
sudo timeout 120s tcpdump -s 0 -A dst port 80
If you want to learn more about timeout:
https://explainshell.com/explain?cmd=timeout+120s+tcpdump+-s+0+-A+dst+port+80