Ich benutze Python Telnetlib zu Telnet zu einer Maschine und Ausführen von wenigen Befehlen und ich möchte die Ausgabe dieser Befehle erhalten.Lesen der Ausgabe mit Telnetlib in Echtzeit
Also, was das aktuelle Szenario ist -
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("command1")
tn.write("command2")
tn.write("command3")
tn.write("command4")
tn.write("exit\n")
sess_op = tn.read_all()
print sess_op
#here I get the whole output
Jetzt kann ich alle konsolidierte Ausgabe in sess_op erhalten.
Aber, was ich will, ist die Ausgabe von command1 unmittelbar nach ihrer Ausführung und vor der Ausführung von command2 zu bekommen, als ob ich in der Schale von der anderen Maschine gerade arbeitete, wie hier gezeigt -
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("command1")
#here I want to get the output for command1
tn.write("command2")
#here I want to get the output for command2
tn.write("command3")
tn.write("command4")
tn.write("exit\n")
sess_op = tn.read_all()
print sess_op
es funktioniert nicht in meinem Fall! – theharshest