I want to use pexpect to check file contents by inodes through debugfs.
The simple, obvious... and wrong way of doing that would be to expect the “debugfs: ” prompt and then analyze the .before string. However, doing that will obviously cause a buffer or memory overflow for the very large files. Is there a "right" way to read (and process) my output block by block until I get the matching content ?
I have found the following way, but it's not very efficient:
import pexpect
cat=pexpect.spawn("debugfs -cD -R 'cat <123456>' /dev/md0", timeout=600)
patterns = ["debugfs: ", "^.{"+str(2**20)+"}"]
while cat.expect(patterns)==1:
print(len(cat.before), len(cat.after), len(cat.buffer))
print(len(cat.before), len(cat.after), len(cat.buffer))