-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcowBufferFix.py
More file actions
executable file
·58 lines (41 loc) · 1.87 KB
/
cowBufferFix.py
File metadata and controls
executable file
·58 lines (41 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
import subprocess,re,glob,mmap
# Create list of agents and store in agentList
agents = subprocess.Popen(('snap***', 'list'), stdout=subprocess.PIPE)
output = agents.communicate()[0]
agentList = ' '.join(output.splitlines()).split()[0::2]
print "\nAll agents:",agentList
# Search for agents with a cowBuffer file already. Don't search for them.
myAgents = []
for file in glob.glob("/d****/config/keys/*.cowBuffer"):
filename = file.rstrip(".cowBuffer")
filename = filename.lstrip("/d****/config/keys/")
myAgents.append(filename)
# Compare the lists and only search for those without a cowBuffer fix
# and print the names
newList = list(set(agentList).difference(myAgents))
print "Agents without cowBuffer fix:",newList,"\n"
# Iterate through the list, find matches greater than 200 once.
# If value is found, create the file.
# For future, add ability to search through gz files.
for agent in newList:
print "Looking for matches for agent: " + agent
agentFilename = "/d****/config/keys/" + agent + ".log"
agentLog = open(agentFilename, 'r')
# Create mmap as this is much faster than loading whole agent log
# into memory. Perform regex search and put into capture group.
s = mmap.mmap(agentLog.fileno(), 0, access=mmap.ACCESS_READ)
reg = re.compile("Creating ([2-9][0-9][0-9]) megabyte cow")
m = reg.search(s)
agentLog.close()
# If match is found, create file. If not, print no match
if m:
print "Found " + m.group(1) + " megabyte cow file!"
fname = "/d****/config/keys/" + agent + ".cowBuffer"
print "Creating file for agent " + agent + "..."
f = open(fname, 'w')
f.write("2000\n")
f.close()
print "Done!\n"
else:
print "No Match\n"