Get_Baseline/getbaseline_CP.py

53 lines
1.7 KiB
Python
Raw Permalink Normal View History

2023-08-29 01:16:23 +07:00
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()
2025-11-13 20:18:23 +07:00
log_file = (
"D:/Visual Studio Code/GetBaseLine/Result/Remove_member1_CDN_VNPT_NTL.txt"
)
2023-08-29 01:16:23 +07:00
with open(log_file, "a") as log:
try:
time.sleep(2)
2025-11-13 20:18:23 +07:00
# logtime = datetime.datetime.now()
# log.write(str(logtime))
# log.write("\n\n---------------------------------------------------------------------------------------------------------------------------\n")
2023-08-29 01:16:23 +07:00
for command in commands_list:
2025-11-13 20:18:23 +07:00
crt.Screen.Send(command + "\n")
2023-08-29 01:16:23 +07:00
response = crt.Screen.ReadString(">")
2025-11-13 20:18:23 +07:00
# log.write( response)
2023-08-29 01:16:23 +07:00
log.write("> " + command + response)
2025-11-13 20:18:23 +07:00
time.sleep(1)
2023-08-29 01:16:23 +07:00
except Exception as e:
log.write("Error occurred: " + str(e))
crt.Dialog.MessageBox("Error occurred: " + str(e))
def main():
2025-11-13 20:18:23 +07:00
with open("D:\Visual Studio Code\GetBaseLine\ip_device.txt", "r") as commands:
2023-08-29 01:16:23 +07:00
dataIP = commands.read()
list_ip_device = dataIP.splitlines()
for ip in list_ip_device:
crt.Screen.Send("ssh haudt3@%s \n" % (ip))
2025-11-13 20:18:23 +07:00
# time.sleep(0.5)
# crt.Screen.Send("yes\n")
2023-08-29 01:16:23 +07:00
crt.Screen.WaitForString("assword:")
2025-11-13 20:18:23 +07:00
crt.Screen.Send("Hau@vng210701\n")
2023-08-29 01:16:23 +07:00
crt.Screen.WaitForString(">")
2025-11-13 20:18:23 +07:00
time.sleep(1)
2023-08-29 01:16:23 +07:00
getInfo()
crt.Screen.Send("quit \n")
2025-11-13 20:18:23 +07:00
crt.Screen.WaitForString("[haudt3@DC_CP_TERMINAL_PRI ~]$")
time.sleep(1)
2023-08-29 01:16:23 +07:00
crt.Dialog.MessageBox("Script completed. Check the log for details.")
main()