checking in so i don't lose this snippet, but i need to do this totally different.

This commit is contained in:
brent s 2017-10-09 09:18:37 -04:00
parent f47f2f8640
commit e74c554643
1 changed files with 44 additions and 0 deletions

44
storage/badblocks.py Normal file
View File

@ -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()