LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   can we telnet the system using shell script (https://www.linuxquestions.org/questions/programming-9/can-we-telnet-the-system-using-shell-script-291697/)

suchi_s 02-18-2005 12:58 AM

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

druuna 02-18-2005 03:26 AM

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.

Libu 02-18-2005 03:35 AM

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


suchi_s 02-18-2005 03:39 AM

how to do with .netrc file.. what all i have to do

druuna 02-18-2005 03:45 AM

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.

suchi_s 02-18-2005 03:46 AM

how to create this file it does not reside in home

druuna 02-18-2005 03:49 AM

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.

suchi_s 02-18-2005 03:53 AM

how to run it.. does it do the file transfer and how ?
what is the complete procedure?

jlliagre 02-18-2005 03:56 AM

.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.

suchi_s 02-18-2005 04:08 AM

can i ftp a system through some gateway

jlliagre 02-18-2005 04:21 AM

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.

Libu 02-18-2005 04:22 AM

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.

suchi_s 02-18-2005 04:23 AM

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

jlliagre 02-18-2005 04:32 AM

Forget telnet and ftp.
Code:

ssh gateway scp othersystem:/somefile /somedir

suchi_s 02-18-2005 04:34 AM

i dint get it..
how to do?


All times are GMT -5. The time now is 10:34 PM.