LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   telneting remote machine from a shell script (https://www.linuxquestions.org/questions/programming-9/telneting-remote-machine-from-a-shell-script-183231/)

sanjith11 05-19-2004 06:58 AM

telneting remote machine from a shell script
 
hi all.

Is ther any method to Telnet to a remote machine from a unix shell script.
How to Authenticate after the connection establishment,. ie how can i supply username and password at the required movment.


thanx
san

philipz 05-19-2004 09:00 AM

You should have a look at TCL, it has an 'expect' function which will wait for a certain prompt.

pcardout 05-19-2004 11:23 PM

I'm not sure what you want to do once you telnet. As an older geek, Telnet was in my comfort zone, but the younger generation has made me see the joys of scp (secure copy)
and ssh (secure shell). ssh has all the functionality of telnet, plus more. You end up sitting in a
remote shell. I had reason to use scp, because I wanted to copy files
across a network on a regular basis (as a cron job) in an automated way.
What both scp and ssh have in common is that they have a method of
logging on without a password, which eliminates the hassle of needing to type a password in the middle of your shell script.

Here's how the magic happens:

/usr/bin/scp -q richard@kilgore.trout.edu:1KBYTE /home/richard/1KBYTE
#A line from my cron script that copies a file from my local machine to my
#"richard" account on kilgore. The -q suppresses chatter.

Now you ask ... how can this work? Where is the security?
scp and ssh work on private and public keys. There is a command called
ssh-keygen that you have to run both on your local system and on the
system you want to regularly contact without the need to login.
If you run ssh-keygen, your key will be cached locally and on the host machine (securely ... believe it or not, due to the magic of RSA). When your
local machine tries to get to the remote machine, the remote just checks
the already cached key, and lets you in w/o a password. This is secure because you needed passwords on both accounts in order to set this
up to begin with. It assumes that anyone logged on as you on your
machine has rights to any other machines you care to access. That's fair.

It took me several hours to figure out ssh-keygen. If you ask, I'll give you another hint or two, but didn't want to waste time if this whole thing won't work for you. (Like for instance if you're stuck w/ telnet because you're
trying to get to a Windows machine ... then you are SOL, buddy!)

sanjith11 05-20-2004 01:01 AM

thanx for that.. but here i need to telnet and run some scripts in the remote machine...and also there is no chance of logging in without the password.

jschiwal 05-20-2004 05:52 AM

I think that you need to use the -a option for autologin. Also the line 'set autologin' needs to exist in the remote machines .telnetrc file to allow autologins. Does the remote machine use kerebos authentication. If so, that needs to be set up.
Is the remote machine on the local network, with no internet connection? Are all of the users on the network totally trustworthy. Otherwise, I can't believe that the remote machine is running the telnet service!

sanjith11 05-20-2004 07:41 AM

the system is highly secure and autologin cannot be used here.the connection to the server is done via inter net and it runs the telnet service.

presently i use Reflection X to connect to these servers.

BUt i need to automate it for ease of use.

Hko 05-20-2004 08:54 AM

A "highly secure" system does not run the telnet service...

Try if if you can connect to the server with "rsh" or "rlogin". These are old, deprecated remote shell-services, which do not require a password. If the system serves rsh or rlogin, this could solve your problem I think, though I expect the server doesn't allow this. It's even more insecure than "telnet"...

keefaz 05-21-2004 03:34 PM

try Net::Telnet CPAN module for perl, I use for comunicate with my router, I do a loop in a perl script to open port range in my router which does not have the port range feature. I hard coded the router password in the perl script.

sanjith11 05-24-2004 10:06 AM

But how can i add a new module in to my perl system...

i tried it but its goin on asking for diffrent modules..

keefaz 05-24-2004 11:02 AM

http://cpan.org/modules/by-module/Ne...et-3.03.tar.gz
untar file; do Perl Makefile.pl; make; make install (as root)

For get rid of dependency you may try as root :

perl -MCPAN -e 'install Bundle::CPAN'

which will install/upgrade all needed perl package

edit : I find the good url

LuggerHouse 05-25-2004 08:44 AM

If you the security of you server is quite tight but you can still have a public key:

you will be able to:

ssh yourMachine -l yourUsername yourRemoteScriptWithFullPath

Ex:

ssh 192.168.0.1 -lroot /etc/init.d/network restart;/etc/init.d/network status

sanjith11 05-26-2004 06:50 AM

thanx..


All times are GMT -5. The time now is 12:48 AM.