Stupid Simple Python Script For Working With System vs ZFS Disks

Submitted by gpmidi on Thu, 10/10/2019 - 09:42

This script helps identify what disks are in use (or not in use) by ZFS. It's a stupid-simple python 3 script that requires only 'sh'. You can get that via 'pip3 install sh'. 

import re
from sh import zpool,lsblk,ls
from pprint import pprint

print("Finding all disks")
sdisks = str(lsblk('-d').stdout)
# sdbl  67:240  0   7.3T  0 disk
alldisks = re.findall(r'(sd[a-z]+)\s+\d+:\d+\s+\d+\s+(.*?)\s+\d+\s+disk',sdisks,re.MULTILINE)
print("Found %d disks on system"%len(alldisks))