Solved

how to use script to manage telnet session

Posted on 1997-10-17
5
363 Views
Last Modified: 2013-12-23
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)
0
Comment
Question by:gaddish
  • 3
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1582719
Do you have
man expect
on your system?
0
 
LVL 5

Accepted Solution

by:
n0thing earned 100 total points
ID: 1582720
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
 

Author Comment

by:gaddish
ID: 1582721
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
 
LVL 84

Expert Comment

by:ozo
ID: 1582722
n0thing's method should work for sending commands too,
assuming those commands can be sent blindly.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1582723
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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Let’s list some of the technologies that enable smooth teleworking. 
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

778 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