Solved

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

Posted on 2000-03-02
8
640 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
 

Author Comment

by:kitwei
ID: 2584088
will try next week, thx
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

21 Experts available now in Live!

Get 1:1 Help Now