TELNET using UNIX Shell Scripting

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

jhunmacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
Use wget, a Perl script or an expect script instead.
0
jhunmacAuthor Commented:
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
TintinCommented:
There is no easy or reliable way of scripting it.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jhunmacAuthor Commented:
OK, Thanks very much for your time.
0
TintinCommented:
Can I ask why you don't want to use a suitable tool for the task?
0
jhunmacAuthor Commented:
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
TintinCommented:
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
jhunmacAuthor Commented:
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
jimbbCommented:
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
jhunmacAuthor Commented:
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
TintinCommented:
I think HP/UX is one of those systems where you can't use STDIN with telnet.
0
jhunmacAuthor Commented:
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
TintinCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
liddlerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.