Solved

Script to establish telnet connection and output results to text file

Posted on 2007-11-19
2
4,387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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