Solved

Telnet Scripting Question

Posted on 2008-10-31
7
656 Views
Last Modified: 2012-05-05
I have a weather system with an RS232 port that you can run queries and get the current temperature.  I recently installed fogsoft.com's Serial/IP server that basically acts as a telnet to rs232 bridge.  I am wanting to run a script twice a day that will telnet to the device, run some commands, and save the output to a file.   I will then email that file twice a day as well.

To get it to work manually, I have to run the following commands:

1. telnet
2. set escape ?  (could be anything but ? was the easiest)
3. open example.domain.com 2000  (uses port 2000 for telnet)
4. ?  (? key switches back to telnet> )
5. mode character (this server only supports character mode, without this, the results are never displayed)
6. atn

Once your type atn and press enter, it displays the current temperature.

I have spent hours trying to dig through scripting examples, but can never get past the part where it connects to the server.

This is what I have so far:

( echo "?"
sleep 1
echo "mode character"
sleep 1
echo -e "\r"
sleep 1
echo "atn"
sleep 1
echo -e "\r"
sleep 1
sleep 10
) | telnet -e ? vpn.alpinecomm.com 2000


Any thoughts?  Your help is much appreciated!


Brandon M.
0
Comment
Question by:renvorak
7 Comments
 
LVL 8

Expert Comment

by:Rance_Hall
ID: 22854190
Ive never had much success with bash against things like ftp and telnet, yes there are ways to do it, but in my limited experience they were kludges at best and not easily portable across boxes.

in come scripting languages with modules specifically designed for telnet

like kermit, or some of the specific modules of php, python, perl, etc.

I have personal experience with php and kermit, but any of the modern scripting languages can help you.
0
 
LVL 1

Expert Comment

by:d4t2ill4
ID: 22854221
0
 
LVL 1

Expert Comment

by:d4t2ill4
ID: 22854230
0
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 250 total points
ID: 22872519
The classic way to run telnet in a script is to use expect. The documentation has a telnet login as an example.
http://expect.nist.gov/
0
 
LVL 1

Author Closing Comment

by:renvorak
ID: 31512200
Partially worked, but got me on the right track.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

756 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