The below command is running one time and saves abc.pcap to directory. I want the below command to run continous and make pcaps of five second but file names should be different, it continously make 5 sec pcaps untill I stop it.
from subprocess import run
command = 'tcpdump -i eno1 -w abc.pcap'
output = run(command, capture_output=True, shell=True, timeout=5).stdout.decode()
print(" capture packet for 5 seconds")
Traceback (most recent call last):
File "one.py", line 17, in <module>
output = run(command.format(str(file_counter)), capture_output=True, shell=True,timeout=5).stdout.decode()
File "/usr/lib/python3.8/subprocess.py", line 491, in run
stdout, stderr = process.communicate(input, timeout=timeout)
File "/usr/lib/python3.8/subprocess.py", line 1024, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/usr/lib/python3.8/subprocess.py", line 1867, in _communicate
self._check_timeout(endtime, orig_timeout, stdout, stderr)
File "/usr/lib/python3.8/subprocess.py", line 1068, in _check_timeout
raise TimeoutExpired(
subprocess.TimeoutExpired: Command 'tcpdump -i eno1 -w abc_0.pcap' timed out after 5 seconds