Solved

Telnet Scripting Question

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

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

Secure Shell (SSH) is a network protocol for secure data communication, mainly used to administer remote Unix / Linux servers via command line. But it also allows the user to open a secure tunnel between a client and a server where he can send any k…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

860 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