I connect to a Cisco router using telnet.
The connection times out every 3 minutes.
How do stop my telnet session from getting disconnected from the router due to a timeout.
I understand that putty and SecureCRT can send a null or escape character periodically to stop the session (telnet or SSH) from timing out.
How do I do this on Linux without a 3rd party program ? I use the following script as a startup script when starting my terminal:
#!/usr/bin/expect -f spawn telnet <Router IP Address> expect -re "ogin: " send "*******\n" expect -re "assword:" send "***********\n" sleep 2 expect "Router>" interact
Answer
The interact
statement of expect
can take pairs of patterns and actions somewhat like the expect
statement. In particular, you can add a timeout pattern and an action of sending. For example,
interact timeout 10 { send "date\r" }
would send what you type as usual, but if you do not type for 10 seconds, it will then send the string date
and carriage-return. If you are using telnet, in char mode, you might be able to keep the connection alive by simply sending a space followed by a backspace, which would not disrupt any partial line you had already typed:
interact timeout 150 { send " \b" }
Attribution
Source : Link , Question Author : Khaled Abuelenain , Answer Author : meuh