Skip to content

Instantly share code, notes, and snippets.

@jhaubrich
Last active August 29, 2015 13:56
Show Gist options
  • Save jhaubrich/9008222 to your computer and use it in GitHub Desktop.
Save jhaubrich/9008222 to your computer and use it in GitHub Desktop.
from subprocess import Popen, PIPE
p = Popen(['tail', '-f', 'popen_test'], stdout=PIPE)
p.stdout.readline() # will block until there is something to be read
# Then just `echo "hello world!" >> popen_test
#!/bin/usr/env python
'''
Usage:
pcap_tender.py <feed> <iface> [--debug]
Options:
-h, --help Print this screen.
-v, --version Print the version
--debug Verbose output, and don't actually move anything.
'''
from subprocess import Popen, PIPE
from datetime import datetime
import re
from docopt import docopt
def copy_to_wmd(filename):
''' Copy a given file to /wmd
'''
pass
def initiate_dumpcap(args):
''' start dumpcap with -a duration=<time_remaining_until_5min_marker>
'''
pass
def monitor_dumpcap(args):
''' start the dumpcap process and monitor the output
Dumpcap produces the following output while it works.
The first two lines when it starts, and the following two when
it finishes:
```
Capturing on eth1
File: /data/noc1_04219_20130718114010.pcapng
Packets captured: 181094
Packets received/dropped on interface eth1: 181094/64 (100.0%)
```
'''
c = "tail -f test_process"
p = Popen(c.split(), stdout=PIPE, stderr=PIPE)
for line in p.stdout.readlines():
if re.match("File: ", line) :
# save filename for currently written file
if re.match("Packets captured"):
# we're done with the file
copy_to_wmd(filename) # copy freshly created file to wmd
if __name__ == '__main__':
args = docopt(__doc__, version='PCAP Tender 0.01')
print(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment