From bac18d879168a44ca88ab895e87913908f950945 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 15 Sep 2020 23:16:27 +0200 Subject: Add smartctrl capture to python hw script --- modules.d/bas-python/module-setup.sh | 2 +- modules.d/bas-python/scripts/00collect_hw_info_json.py | 9 ++++++--- modules.d/bas-python/scripts/00reboot_script.sh | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules.d/bas-python/module-setup.sh b/modules.d/bas-python/module-setup.sh index 2cec109f..4fa8b260 100755 --- a/modules.d/bas-python/module-setup.sh +++ b/modules.d/bas-python/module-setup.sh @@ -34,7 +34,7 @@ install() { inst_hook pre-mount 00 "$moddir/scripts/00collect_hw_info_json.py" # Call finish script instead of Switch Root - inst_hook cleanup 00 "$moddir/scripts/00reboot_script.sh" + inst_hook pre-mount 00 "$moddir/scripts/00reboot_script.sh" return 0 } diff --git a/modules.d/bas-python/scripts/00collect_hw_info_json.py b/modules.d/bas-python/scripts/00collect_hw_info_json.py index 7f57e9e2..552840bc 100755 --- a/modules.d/bas-python/scripts/00collect_hw_info_json.py +++ b/modules.d/bas-python/scripts/00collect_hw_info_json.py @@ -3,13 +3,13 @@ import json import subprocess import sys import argparse +from os import listdir __debug = False # Run dmi command as subprocess and get the stdout def run_subprocess(_cmd): global __debug - proc = subprocess.Popen(_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = proc.communicate() if __debug: @@ -54,8 +54,11 @@ def main(): if isinstance(_dmidecode, str): _collecthw['dmidecode'] = json.loads(_dmidecode) - # _smartctl = run_subprocess('smartctl --json') - + # Get Smartcontrol info + # TODO: error handling + disks = listdir('/dev/disk/by-path/') + filteredDisks = [i for i in disks if (not "-part" in i) and (not "-usb-" in i)] + _collecthw['smartctl'] = [json.loads(subprocess.run('smartctl -x --json /dev/disk/by-path/' + d, shell=True, capture_output=True).stdout.decode()) for d in filteredDisks] print(json.dumps(_collecthw)) if __name__ == "__main__": diff --git a/modules.d/bas-python/scripts/00reboot_script.sh b/modules.d/bas-python/scripts/00reboot_script.sh index 2ca40949..2ae7ca55 100755 --- a/modules.d/bas-python/scripts/00reboot_script.sh +++ b/modules.d/bas-python/scripts/00reboot_script.sh @@ -1,6 +1,10 @@ #!/bin/bash echo "°(^.^)° Everything finished (hopefully) successfull" + +# . /lib/dracut-lib.sh +# emergency_shell + read -p "Press Enter to reboot" reboot -- cgit v1.2.3-55-g7522