From e74c5546435f8501dfcd0c218b3768f6e9b52b03 Mon Sep 17 00:00:00 2001 From: brent s Date: Mon, 9 Oct 2017 09:18:37 -0400 Subject: [PATCH] checking in so i don't lose this snippet, but i need to do this totally different. --- storage/badblocks.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 storage/badblocks.py diff --git a/storage/badblocks.py b/storage/badblocks.py new file mode 100644 index 0000000..1729364 --- /dev/null +++ b/storage/badblocks.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +# Email alerts about disks if there are any errors found. +# It can take a LONG time depending on the speed/type of disk and size of disk. +# Should probably only cron it once a week or so. + +import os +import pycryptsetup +import lvm +import subprocess + +def getDisks(): + disks = [] + for d in psutil.disk_partitions(all = False): + if d.device not in disks: # Avoid dupes + _devpath = os.path.split(d.device) + if _devpath[1] == 'mapper': # It's actually an LVM, LUKS, etc. + # Is it an LVM device? + if lvm.scan(): + continue + # Is it a LUKS device? + _crypt = pycryptsetup.CryptSetup(d.device) + if _crypt.isLuks() == 0: + # We can (and should) get the actual physical device + _dev = _crypt.info()['device'] + if _dev not in disks: + disks.append(_dev) + else: + disks.append(d.device) + return(disks) + +def chkDisk(disk): + pass + +def main(): + pass + +def userChk(): + # Needs to be run as root/with sudo, because of e.g. cryptsetup, etc. + if os.geteuid() != 0: + raise PermissionError('This script must be run with root privileges.') + +if __name__ == '__main__': + main()