how to use script to manage telnet session

how to use telnet in a Unix script?
I wish to insert telnet commands in a telnet session using a script to both open the telnet session and insert the telnet commands.(redirection doesn't work)
gaddishAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
n0thingConnect With a Mentor Commented:
Hi,

  Here's a sample script on how to use telnet in a script.
This script will simply log in a system & logout.
  Hope this's what you need. Another choice is to install expect
like ozo said, much more powerfull scripting capability.

Regards,
Minh Lai

#!/bin/sh
# Telnet to host and logout
# Usage: stelnet hostname
#
# If ping reachable (Under Solaris 2.5.x)
if ping $1 3
then
{
echo john          # send login
sleep 2            # wait 2 seconds for answer
echo john_passwd   # send passwd
sleep 2
echo logout        # logout of the system
} | telnet $1
fi

0
 
ozoCommented:
Do you have
man expect
on your system?
0
 
gaddishAuthor Commented:
HI n0thing,
Thank you for your answer.I guess I wasn't clear enough about my question, though. My problem is not how to establish a telnet session using a script, but how use a script to send telnet commands and parameters once I'm in the session already.
0
 
ozoCommented:
n0thing's method should work for sending commands too,
assuming those commands can be sent blindly.
0
 
ozoCommented:
Another way to execute commands on a remote system is with rsh.
Or, if you have expect (or want to install it) it can be used to
conduct a dialog with an interactive telnet progam.
0
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.

All Courses

From novice to tech pro — start learning today.