Link to home
Start Free TrialLog in
Avatar of jhunmac
jhunmac

asked on

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

Avatar of Tintin
Tintin

Use wget, a Perl script or an expect script instead.
Avatar of jhunmac

ASKER

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.
There is no easy or reliable way of scripting it.
Avatar of jhunmac

ASKER

OK, Thanks very much for your time.
Can I ask why you don't want to use a suitable tool for the task?
Avatar of jhunmac

ASKER

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?
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");
Avatar of jhunmac

ASKER

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.
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.
Avatar of jhunmac

ASKER

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.
I think HP/UX is one of those systems where you can't use STDIN with telnet.
Avatar of jhunmac

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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