ogclone-engine/ogclient/interfaceAdm/InventarioHardware.py

26 lines
759 B
Python

#!/usr/bin/python3
# Script de interfaz para guardar en un fichero el inventario de hardware de un cliente.
import sys
import subprocess
import ogGlobals
from SystemLib import ogRaiseError
prog = sys.argv[0]
if len (sys.argv) != 2:
print (f'Usage: {prog} <output_file>')
sys.exit (1)
output_file = sys.argv[1]
listhi_out = subprocess.run ( [f'{ogGlobals.OGSCRIPTS}/listHardwareInfo.py'], capture_output=True, text=True).stdout
if listhi_out:
inventory_path = listhi_out.splitlines()[0]
else:
ogRaiseError ([], ogGlobals.OG_ERR_GENERIC, 'listHardwareInfo.py failed')
sys.exit (1)
with open (inventory_path, 'r') as fdin, open (output_file, 'w') as fdout:
lines = fdin.readlines()[1:] # 'tail -n +2'
fdout.writelines (lines)