?
Solved

TELNET using UNIX Shell Scripting

Posted on 2003-02-26
15
Medium Priority
?
4,092 Views
Last Modified: 2013-12-26
Hi!

Can anyone help me with regards to running a telnet in a script file. Below is the code:

#!/bin/sh                    
telnet 192.168.1.34 8888      
get /claims/index.jsp HTTP/1.0

If a try the said script in a manual or line-to-line prompt, it would work properly. But when I run the said script it would never execute the "get /claims/index.jsp HTTP/1.0".

It would display the following messages:
Trying...                                        
Connected to 192.168.1.34.                      
Escape character is '^]'.                        
Connection closed by foreign host.              
ERROR [/claims/index.jsp]: not an SCCS file (co1)
ERROR [HTTP/1.0]: not an SCCS file (co1)        

Please help, I need it ASAP.

Thanks

0
Comment
Question by:jhunmac
[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
15 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 8031309
Use wget, a Perl script or an expect script instead.
0
 

Author Comment

by:jhunmac
ID: 8031363
Tintin,

Is it possible if I would not use the Perl or except script? Can it be handled by UNIX Shell Scripting only? The only problem is how to indicate the "Enter" key at the script.


Thanks.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 8031414
There is no easy or reliable way of scripting it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jhunmac
ID: 8031425
OK, Thanks very much for your time.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 8032017
Can I ask why you don't want to use a suitable tool for the task?
0
 

Author Comment

by:jhunmac
ID: 8032058
It's not that I want to use the said tool but I'm trying to see if I can manipulate the said script using the UNIX Shell Scripting. I want to see if I can solve the said problem without using the suitable tool for the ask. Also, I must download the said tool. Are the suitable tools you are suggesting easily to use? I haven't used the said tools yet. And if the said tools are easy to use, can you guide a little bit?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 8032127
With the right tools, it's simple.

What OS are you using?

Here's a simple script using wget

#!/bin/sh
wget -q -O - http://192.168.1.34:8888/claims/index.jsp 

Here's the Perl equivalent

#!/usr/bin/perl
use LWP::Simple;
getprint("http://192.168.1.34:8888/claims/index.jsp");
0
 

Author Comment

by:jhunmac
ID: 8032192
I'm using HP-UX v11.00. By the way if I would used the expect, how should I code it? I would try to download the wget, Perl and the expect tools.

Thanks.
0
 
LVL 2

Expert Comment

by:jimbb
ID: 8035346
Many *nix Telnet clients (or 'nc' (netcat) if you have it) can take stdin and send it to the remote system when the connection is opened.

echo "get /claims/index.jsp HTTP/1.0" | telnet 192.168.1.34 8888
 - or something like that, I think you'd have to also put the carriage returns/line feeds in there.

echo "get /claims/index.jsp HTTP/1.0" | nc 192.168.1.34 8888

same deal.


This is a pretty ugly hack though, you really are better off using wget or something else as Tintin suggested.  Or if you have the LWP Perl module installed, you could use the GET, HEAD, and POST commands it includes.
0
 

Author Comment

by:jhunmac
ID: 8038559
jimbb,

I tried your first recommendation but it still didn't work. How can I put a carriage return/line feed on a script? Do you have any ideas?

Thanks.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 8038744
I think HP/UX is one of those systems where you can't use STDIN with telnet.
0
 

Author Comment

by:jhunmac
ID: 8038871
I've already made some work arounds and the said script works properly. What I did was to create a text file that would store the lines of code below:

get /claims/index.jsp HTTP/1.0
CR
CR

Then create a script that would call the created file. Shown below is the code:

cat script.txt | telnet 192.168.1.34 8888

The said script is working properly.

Thanks for your recommendation/solution.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 200 total points
ID: 8038897
You might be able to do it on a single line with

echo "get /claims/index.jsp HTTP/1.0\n\n\n" | telnet 192.168.1.34 8888
0
 
LVL 18

Expert Comment

by:liddler
ID: 9827093
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by Tintin

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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