Sponsored Link

Many times i've used this website to get useful tips that helped me in ubuntu so I thought of giving back to this great community.

There's a topic always asked about on forums and the answers are typically wrong, unuseful, doesnt work, etc.. I had the same problem, I figured it out so I thought about posting it here. How to save the infamous telnet output automatically to a file on your pc.

In terminal:

Install expect by doing:

sudo apt-get install expect

then, do an expect script of your telnet session, the way you want it. (internet is full of articles about expect scripting, and believe me it's real easy!)

then in terminal launch the script using expect and use the program "tee" to redirect the output to a file on ur pc.

example:

we have an expect script called fetch.

in terminal we do:

expect fetch | tee example.txt

this command will launch connect to telnet, automatically do the commands u put in the fetch script, and send all the output till the end to a file in ur current directory named example.txt

if the operation is a routine (fetching data for example regularly) u can add the command to cron to schedule it to run anytime u want automatically and save u the output data.

to do that enter crontab -e in terminal and add the job there, or alternatively do:

sudo apt-get install gnome-schedule

and edit cron graphically, but needless to say, the terminal gives u a wider set of control and options on cron.

4 thoughts on “How to save the output of your telnet session”

Install the “script” command. Then first run script from a terminal, followed by the telnet command. When your telnet session is over press ^D, and — voila! — input and output from your telnet session can be found in the file “typescript” in the current directory. No need for expect.