?
Solved

shell script, feed telnet, rlogin, or rsh with login

Posted on 2000-03-02
8
Medium Priority
?
650 Views
Last Modified: 2013-12-26
I'm writing a simple bourne shell script to connect to a host and execute a command, say, ls.
When I run the script, I provide the username at command line.
The problem is telnet prompts for username and passwd. I want to use the username I already have, say, in a variable, to feed it to the login prompt and enter.
The script will have no user interaction after being run.
The script will eventually be called by another file, so username and passwd and command will be provided in variables.
Please provide sample code.
Thanks.
0
Comment
Question by:kitwei
[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
8 Comments
 
LVL 21

Expert Comment

by:tfewster
ID: 2578178
User authentication (telnet login, rlogin, rsh) can't easily be fooled by a shell script; You can either set up hosts.equiv or .rhosts files on all your target machines, or use "expect", a simple scripting tool that waits for a prompt (e.g. "Password:") and then sends the input.

Download "expect" from:
http://dev.scriptics.com/ (sources, binaries, apps & more!)

For a good manual & examples of what you are trying to do, look at:
http://www.oreilly.com/catalog/expect/chapter/ch03.html 

Be careful to remove read permissions for anyone else from your scripts containing the passwords =8-O
0
 

Author Comment

by:kitwei
ID: 2578505
I was learning expect to accomplish the task, and run into a minor problem.
Since an expect file can take in command line arguments, is there another way to access argv #5, instead of this:
send "[lrange $argv 5 5]\n"

If I use $argv5, it will return error...  
0
 
LVL 14

Accepted Solution

by:
mcrider earned 600 total points
ID: 2579011
Scripting a telnet session is really simple... Here is an example that will log into localhost and run the "who" command...

#!/bin/sh
tpipe()
{
sleep 3
echo -e "userid" #REPLACE userid WITH YOUR USERID
sleep 1
echo -e "password" #REPLACE password WITH YOUR PASSWORD
sleep 1
echo -e "who"     #THE COMMAND YOU WANT TO EXECUTE GOES HERE
sleep 1
echo -e "exit"    #LOG OFF TELNET SESSION
sleep 5
}
tpipe|telnet localhost




Cheers!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:kitwei
ID: 2584088
will try next week, thx
0
 

Author Comment

by:kitwei
ID: 2593295
my perl script cannot exec, or system any file, it can run basic ls > tmp/temp command though.
I checked the permission of the files, they are all 777.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2594199
kitwei,

Did you try the shell script? Did your last comment apply to this question?? The question was about "shell" not "perl" wasn't it????


Cheers!®©
0
 
LVL 84

Expert Comment

by:ozo
ID: 2594403
How do you run the file from perl?
Can you run the file from shell?
If you want to telnet from perl, you can
use Net::Telnet ();
0
 

Expert Comment

by:chansek
ID: 2626458
Hello

  Firstly, I would like to know your Unix machine type?? HP-UX, SCO or etc??
Actually, all are almost the same. You may need to modift the scrips a bits.

  For HP-UX:

  You could execute the following command.

  remsh machine-name <command> or
  Assume machine-name=mscim1
  <command>=bdf

  Actual command is:
  remsh mscim1 bdf

  Requirement:
1) Both machines should have the same ID and password.
2) You must add your ID name, password, and remote machine name into .rhost file so that you could execute the remote command without key any ID and password anymore.
   For more detail, you could type:
   man remsh or man -k shell (look for remote shell command description.)
 

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

771 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