LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-19-2004, 07:58 AM   #1
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Rep: Reputation: 15
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
 
Old 05-19-2004, 10:00 AM   #2
philipz
LQ Newbie
 
Registered: Apr 2004
Posts: 25

Rep: Reputation: 0
You should have a look at TCL, it has an 'expect' function which will wait for a certain prompt.
 
Old 05-20-2004, 12:23 AM   #3
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
Posts: 218

Rep: Reputation: 24
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!)
 
Old 05-20-2004, 02:01 AM   #4
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
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.
 
Old 05-20-2004, 06:52 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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!
 
Old 05-20-2004, 08:41 AM   #6
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
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.
 
Old 05-20-2004, 09:54 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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"...

Last edited by Hko; 05-20-2004 at 09:56 AM.
 
Old 05-21-2004, 04:34 PM   #8
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
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.
 
Old 05-24-2004, 11:06 AM   #9
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
But how can i add a new module in to my perl system...

i tried it but its goin on asking for diffrent modules..
 
Old 05-24-2004, 12:02 PM   #10
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
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

Last edited by keefaz; 05-24-2004 at 12:08 PM.
 
Old 05-25-2004, 09:44 AM   #11
LuggerHouse
Member
 
Registered: May 2004
Location: Montreal,QC,Canada
Distribution: Fedora Core 7
Posts: 208

Rep: Reputation: 30
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
 
Old 05-26-2004, 07:50 AM   #12
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
thanx..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script to monitor process on remote machine kencha Linux - Newbie 6 01-07-2005 01:07 PM
Trouble Telneting out of the Machine matrim Linux - Hardware 0 01-04-2005 12:34 AM
Running a script in background on a remote machine TheCoffeeMug Linux - Networking 3 11-06-2003 11:08 AM
F1 keys not working when telneting to SCO machine. Frustin Linux - Software 3 03-13-2003 07:03 AM
No remote Telneting and no Apache hubergeek Linux - Software 1 04-05-2002 02:14 PM


All times are GMT -5. The time now is 01:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration