Terminal export is written into file.

This commit is contained in:
Tilen Čeh 2025-03-08 18:41:33 +01:00
parent dfd25c3a47
commit b3623c8ebe
No known key found for this signature in database

10
main.py
View File

@ -30,13 +30,11 @@ for device in devices:
else:
print("Connected to " + device["HostName"])
#Export config
ssh_client.exec_command("export file=" + device["Location"] + "_" + device["DeviceName"] + ".rsc show-sensitive")
stdin, stdout, stderr= ssh_client.exec_command("export show-sensitive")
print("Export commanded")
time.sleep(10) #Wait for ten seconds to make sure latest export is prepared before download
#Download Config
ssh_client.open_sftp().get(device["Location"] + "_" + device["DeviceName"] + ".rsc", file_path)
print("File downloaded successfully!")
with open(file_path, "w") as f: #write export into file
f.writelines(stdout.readlines())
print("Export written into file")
finally:
# Close the SSH connection