import os import time import shutil import subprocess import sys def main(arg1, arg2, dest_file): start_time = time.time() # Load the engine configurator from the engine.cfg file og_engine_configurate = os.getenv('OGENGINECONFIGURATE') if not og_engine_configurate: with open('/opt/opengnsys/etc/engine.cfg') as f: exec(f.read()) # Clear the temporary files used as log tracking for httpdlog og_log_session = os.getenv('OGLOGSESSION') og_log_command = os.getenv('OGLOGCOMMAND') if og_log_session and og_log_command: with open(og_log_session, 'w') as f: f.write(" ") with open(og_log_command, 'w') as f: f.write(" ") with open(f"{og_log_command}.tmp", 'w') as f: f.write(" ") # Log the start of execution msg_interface_start = os.getenv('MSG_INTERFACE_START') if msg_interface_start: subprocess.run(['ogEcho', 'log', 'session', f"{msg_interface_start} {__file__} {arg1} {arg2}"]) # Get the software info file and copy it to the destination # Call the actual listSoftwareInfo function file = listSoftwareInfo(arg1, arg2) shutil.copy(file, dest_file) # Log the execution time elapsed_time = time.time() - start_time msg_scripts_time_partial = os.getenv('MSG_SCRIPTS_TIME_PARTIAL') if msg_scripts_time_partial: subprocess.run(['ogEcho', 'log', 'session', f" [ ] {msg_scripts_time_partial} : {int(elapsed_time // 60)}m {int(elapsed_time % 60)}s"]) if __name__ == "__main__": if len(sys.argv) != 4: print("Usage: python InventarioSoftware.py ") sys.exit(1) main(sys.argv[1], sys.argv[2], sys.argv[3])