import datetime import os import shutil import time def getInfo(): with open("D:/Visual Studio Code/GetBaseLine/command.txt", "r") as commands: datacmd = commands.read() commands_list = datacmd.splitlines() log_file = "D:/Visual Studio Code/GetBaseLine/Result/C92665.txt" with open(log_file, "a") as log: try: time.sleep(2) logtime = datetime.datetime.now() log.write(str(logtime)) log.write( "\n\n---------------------------------------------------------------------------------------------------------------------------\n" ) for command in commands_list: crt.Screen.Send(command + "\r") response = crt.Screen.ReadString(">") log.write("> " + command + response) log.write(response) except Exception as e: log.write("Error occurred: " + str(e)) crt.Dialog.MessageBox("Error occurred: " + str(e)) def main(): with open("D:/Visual Studio Code/GetBaseLine/ip_device.txt", "r") as commands: dataIP = commands.read() list_ip_device = dataIP.splitlines() for ip in list_ip_device: crt.Screen.Send("ssh haudt3@%s \n" % (ip)) crt.Screen.WaitForString("assword:") crt.Screen.Send("Hau@vng0701\n") crt.Screen.WaitForString(">") time.sleep(2) getInfo() crt.Screen.Send("quit \n") crt.Screen.WaitForString("haudt3@DC_QTSC_TERMINAL_PRI") time.sleep(2) crt.Dialog.MessageBox("Script completed. Check the log for details.") main()