Solved

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

Posted on 2000-03-02
8
642 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
8 Comments
 
LVL 20

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 150 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 120
Whole sheet autoscrub still needed 19 50
isEverywhere  challenge 19 74
how to use laptop or pad camera in vb.net windows application 2 70
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now