Python Scripts: fix disk name identifer
This commit is contained in:
parent
f0435961cb
commit
96bcb72a36
1 changed files with 15 additions and 4 deletions
|
@ -58,16 +58,27 @@ def get_device_info(device):
|
|||
output = subprocess.run(
|
||||
f"sudo smartctl -i {device}", shell=True, capture_output=True, text=True
|
||||
).stdout
|
||||
|
||||
model = serial = "unknown"
|
||||
|
||||
for line in output.splitlines():
|
||||
if any(x in line for x in ["Device Model", "Model Family", "Model Number"]):
|
||||
if any(x in line for x in ["Device Model", "Model Number", "Product"]):
|
||||
model = line.split(":", 1)[-1].strip().replace(" ", "_")
|
||||
elif "Serial Number" in line:
|
||||
elif "Vendor:" in line and model == "unknown":
|
||||
vendor = line.split(":", 1)[-1].strip().replace(" ", "_")
|
||||
model = vendor # temporary, could be combined later
|
||||
elif "Serial Number" in line or "Serial number" in line:
|
||||
serial = line.split(":", 1)[-1].strip()
|
||||
elif "Logical Unit id" in line and serial == "unknown":
|
||||
serial = line.split()[-1].strip()
|
||||
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
if model == "unknown" or serial == "unknown":
|
||||
print("Failed to extract model or serial. Using timestamp for filename.")
|
||||
return f"drive_test_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
||||
return f"{model}_{serial}_test.log"
|
||||
return f"drive_test_{timestamp}.log"
|
||||
|
||||
return f"{model}_{serial}_test_{timestamp}.log"
|
||||
|
||||
|
||||
def show_smart_info(device, log_file):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue