Answer the question
In order to leave comments, you need to log in
How to redirect telnet log to python script with server drop detection?
There is a task to redirect the telnet log to a Python script.
Implemented as follows:
Using expect, I log in to the server
Then I run <./expect-script.sh | ./mypython-script.sh>
But there is one problem. When the telnet server is rebooted, my script bundle doesn't catch the event and nothing happens.
Example expect script:
#!/usr/bin/expect -f
set timeout -1
spawn telnet mytelnet.server
expect "Username: "
send -- "username\r"
expect "Password: "
send -- "Password\r"
expect eof
for line in sys.stdin:
# some magic
line = line.rstrip('\n')
print (line)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question