Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2000-03-02
8
Medium Priority
?
656 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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