I have the following bash command in which I'm taking a tcpdump and then saving the file using the date command. I want to embed this command directly in my Python script instead of having to call the bash script separately.
#!/bin/bash
timeout 2 tcpdump -i eth1 -s 96 -w /usr/src/pcapFiles/dump$(date +%y%m%d-%H%M%S).pcap
I get the following kind of file names when I run the above script, which is just what I need(i.e. the date and time is rendered in the name):
dump131104-191834.pcap
However, I'm having difficulty in replicating the above command from within Python. I have gotten this far with embedding the command in Python. I'm unsure about how to break the date command so that it can render the file name just like the way I need it. The following is my Python command:
tcpd = subprocess.Popen(["timeout", "2", "tcpdump", "-i", "eth1", "-s", "96", "-w", "/usr/src/pcapFiles/dump$(date +%y%m%d-%H%M%S).pcap"], stdout=subprocess.PIPE)
output, err = tcpd.communicate()
With this command I get the following output file names from tcpdump
dump$(date +%y%m%d-%H%M%S).pcap