56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
import os
|
|
import time
|
|
import subprocess
|
|
import sys
|
|
|
|
def main(script_path):
|
|
start_time = time.time()
|
|
|
|
# Load engine configurator from 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 temporary file used as log track by httpdlog
|
|
og_log_session = os.getenv('OGLOGSESSION')
|
|
og_log_command = os.getenv('OGLOGCOMMAND')
|
|
if og_log_session:
|
|
open(og_log_session, 'w').close()
|
|
if og_log_command:
|
|
open(og_log_command, 'w').close()
|
|
|
|
# Registro de inicio de ejecución
|
|
msg_interface_start = os.getenv('MSG_INTERFACE_START')
|
|
og_echo('log session', f"{msg_interface_start} {sys.argv[0]} {' '.join(sys.argv[1:])}")
|
|
|
|
og_log_file = os.getenv('OGLOGFILE')
|
|
if og_log_file:
|
|
with open(og_log_file, 'a') as log_file:
|
|
log_file.write("\n Instrucciones a ejecutar: *****************************\n")
|
|
with open(script_path) as script_file:
|
|
log_file.write(script_file.read())
|
|
log_file.write("\n Salida de las instrucciones: *****************************\n")
|
|
|
|
# Execute the script
|
|
os.chmod(script_path, 0o755)
|
|
retval = subprocess.call([script_path])
|
|
|
|
elapsed_time = time.time() - start_time
|
|
if retval == 0:
|
|
og_echo('log session', f"[100] Duracion de la operacion {int(elapsed_time // 60)}m {int(elapsed_time % 60)}s")
|
|
else:
|
|
og_raise_error('log session', retval)
|
|
og_echo('log session error', "Operacion no realizada")
|
|
|
|
# Registro de fin de ejecución
|
|
msg_interface_end = os.getenv('MSG_INTERFACE_END')
|
|
og_echo('log session', f"{msg_interface_end} {retval}")
|
|
|
|
sys.exit(retval)
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python EjecutarScript.py <script_path>")
|
|
sys.exit(1)
|
|
main(sys.argv[1]) |