I am learning python and trying to connect my satellite decoder using telnet. When I tried to connect my device through telnet python script, I could successfully connected to the device.
But i want to capture/save as well as read the output and logs of device (connected thru telnet) from starting in a text file. Also, i want to send few commands to get the output of the command and store in the text file.
Please kindly help on how to capture and write the output logs of device connected thru telnet connection in a local text file.
Note: Once the password is successful, my device prints some set of logs and it has to capture in the local text file, also the output of commands should also record in the text file.
HOST = "192.131.244.100"
user = "user"
password = "user"
tn = Telnet(HOST)
tn.read_until("Login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
time.sleep(5)
tn.write("lr\n") # lr is command to pause logs
tn.write("version\n") # command to check running software version
tn.write("exit\n")
str_all = tn.read_all()
f = open("C:\\temp\\Logs\\output.txt", 'w')
f.write(str_all)
tn.close()
Not able to read and save all logs from starting. Also, pls. let me know any other way to save telnet output either in putty or teraterm.