Solved

Telnet Scripting Question

Posted on 2008-10-31
7
652 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now