Stupid Simple Python Script For Working With System vs ZFS Disks

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'. 

#!/usr/bin/python3
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))

Tags

Subscribe to ZFS