Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script to establish telnet connection and output results to text file

Posted on 2007-11-19
2
Medium Priority
?
4,396 Views
Last Modified: 2008-02-01
I'm looking to create a script that will do the following:

Connect to several devices (one by one) via telnet, send a couple of commands and save *only* the output of 'status line x' and 'detail line x' to a text file.

To give a better idea, this is what the telnet connection looks like:


~~~~~~~~~~~~~~~~~~~~~~~~

telnet 192.168.1.55
--welcome message --
password prompt > ****** ('password' should be entered by the script)

prompt > status (this 'status' command should be sent by the script)

--status line 1--
--status line 2--
--status line 3--
--status line 4--

prompt > showdetail (this 'showdetail' command should be sent by the script)

--detail line 1--
--detail line 2--
--detail line 3--

prompt > exit

~~~~~~~~~~~~~~~~~~~~~~~~


In the end the output text file should look something like this:

---

device ip: 192.168.1.55
status line 1
status line 4
detail line 3

device ip: 192.168.1.56
status line 1
status line 4
detail line 3

etc...
---
0
Comment
Question by:impersonator
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 total points
ID: 20316118
I'm fairly certain there is no built-in way to do this in Windows (though if there is I'd love to hear about it).

However it should be possible to do it using the free client PuTTY.
http://www.chiark.greenend.org.uk/~sgtatham/putty

It includes a command-line tool called Plink which supports batch scripting.
http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter7.html#plink
0
 

Author Comment

by:impersonator
ID: 20637050
I had already found plink before posting :o).  I ended up using a batch script that calls Expect (http://expect.nist.gov/) + plink to connect to the telnet server then saves the output to a temporary text file which later gets parsed to create the output I want.

thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question