LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-18-2005, 12:58 AM   #1
suchi_s
Member
 
Registered: May 2004
Posts: 133

Rep: Reputation: 15
can we telnet the system using shell script


code to telnet the system and pass user name and password through shell script.. is it possible?
it can be done using expect..
is it possible through shell script
 
Old 02-18-2005, 03:26 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

This are 2 ways of doing it:

1) using a HERE document
Code:
telnet  some.site.com <<-HERE
  command
  command
  .
  .
  command
  exit
HERE
Everything between HERE and HERE is given to telnet and executed by telnet.

2) Echoing to telnet
Code:
{
  echo "command"
  echo "command"
  echo "exit"
} | telnet some.site.com
Hope this gets you going again.
 
Old 02-18-2005, 03:35 AM   #3
Libu
Member
 
Registered: Oct 2003
Location: Chennai
Distribution: Slackware 12.1
Posts: 165

Rep: Reputation: 36
I dont thing we can pass the password and login through telnet ( even if this is possible, I guess its not a very good idea at all !) The only way we can do this is by using .netrc file in $HOME/.netrc.
The format of a .netrc file
Code:
machine xxx.x.com
login xxx
password xxxxx
 
Old 02-18-2005, 03:39 AM   #4
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
how to do with .netrc file.. what all i have to do
 
Old 02-18-2005, 03:45 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

@Libu: I don't have telnet (client/sserver) installed, so I could not try it out, but it works for sql/ftp including the user/password part (on the other hand it does not for ssh).

I do agree that telnet is unsave and shouldn't be used, but that was not the question the OP asked And even a .netrc file is unsave.

The .netrc solution you (Libu) gave is an elegant way of doing it. Although I don't know if it'll work for telnet, never tried. It does for ftp, that's for sure.
 
Old 02-18-2005, 03:46 AM   #6
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
how to create this file it does not reside in home
 
Old 02-18-2005, 03:49 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Use you fav editor and create it:

vi ~/.netrc

fill it with the appropriate commands (machine xxx.x.com, login xxx, password xxxxx) each on its own line.

Hope this helps.
 
Old 02-18-2005, 03:53 AM   #8
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
how to run it.. does it do the file transfer and how ?
what is the complete procedure?
 
Old 02-18-2005, 03:56 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
.netrc is for ftp only and doesn't apply to telnet (as far as I know).
There's a .telnetrc file, but not suitable to pass credentials
You should use rlogin/rsh instead, or better ssh which all allow non-interactive login.
 
Old 02-18-2005, 04:08 AM   #10
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
can i ftp a system through some gateway
 
Old 02-18-2005, 04:21 AM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Yes, you can ftp to a system through either an http or a socks proxy.

PS: You should have better started another thread as this last question has nothing to do with the initial one.
 
Old 02-18-2005, 04:22 AM   #12
Libu
Member
 
Registered: Oct 2003
Location: Chennai
Distribution: Slackware 12.1
Posts: 165

Rep: Reputation: 36
Oops, yes the .netrc was for ftp and not telnet . I overlooked that. Sorry for wasting your time.

As for telnet, using expect is the only answer that I can think off ! Dont know of anyother way, you can automate logging to another machine through telnet.

Last edited by Libu; 02-18-2005 at 04:24 AM.
 
Old 02-18-2005, 04:23 AM   #13
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
i want to write the script which would first telnet the gateway from local system and then from gateway will do the ftp on other system
 
Old 02-18-2005, 04:32 AM   #14
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Forget telnet and ftp.
Code:
ssh gateway scp othersystem:/somefile /somedir
 
Old 02-18-2005, 04:34 AM   #15
suchi_s
Member
 
Registered: May 2004
Posts: 133

Original Poster
Rep: Reputation: 15
i dint get it..
how to do?
 
  


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
telnet windows m/c from unix shell script ann124 Programming 1 11-10-2004 02:26 PM
shell script to autologin into a telnet session eastj1974 Linux - General 1 11-17-2003 08:58 PM
PB launching shell-script with telnet Naurore LinuxQuestions.org Member Success Stories 1 08-04-2003 08:42 AM
PB launching shell-script with telnet Naurore Linux - Newbie 1 08-04-2003 05:45 AM
telnet login via shell script lethe Linux - General 8 05-13-2002 10:31 AM


All times are GMT -5. The time now is 01:44 PM.

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