PageRenderTime 64ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/linux/python/tct/summon.py

https://bitbucket.org/jmstagg/snippets
Python | 34 lines | 20 code | 10 blank | 4 comment | 7 complexity | 1e72d69330c56d1d82bda14b5af515c7 MD5 | raw file
  1. #!/usr/bin/python
  2. import sys, os, subprocess, re
  3. """
  4. Supply with a dd image of a fs and a tct timeline we recover all files listed by inode in the timeline using icat
  5. """
  6. def runCommand(cmd):
  7. print "\nExecuting Command:\n\n\t {c}\n\nOutput:\n".format(c=cmd)
  8. print subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout.read()
  9. def main(argv):
  10. if len(argv) < 4:
  11. sys.stderr.write("\nUsage: %s <hdax.dd> <timeline> <icat path>\n" % (argv[0],))
  12. return 1
  13. if not os.path.exists(argv[1]) or not os.path.exists(argv[2]) or not os.path.exists(argv[3]):
  14. sys.stderr.write("\nERROR: input file was not found!\n")
  15. return 1
  16. inputFile = file(argv[2], "r")
  17. icatPath = argv[3]
  18. for line in inputFile:
  19. m = re.search('(?<=-)\d+', line.strip().split("<")[1])
  20. if m:
  21. print "recovering Inode: %s" % m.group(0)
  22. runCommand("%s %s %s > %s" % (icatPath, argv[1], m.group(0), m.group(0)))
  23. if __name__ == "__main__":
  24. sys.exit(main(sys.argv))