Using telnet inside a ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using telnet inside a ksh
# 1  
Old 11-26-2009
Data Using telnet inside a ksh

Hello,

i am trying to use telnet inside of a ksh script.
i would like to do like the following:
Code:
#!/bin/ksh
...
user="user"
hostname="hostname"
telnet -l $user $hostname |&
wait
#end of the ksh

and with this piece of code, i would like to telnet another machine, and let the user use telnet to work on the other machine.
It's like if the command was typed directly into the command prompt: the user then enters the password and continues working on the other machie until he types "exit" then he returns back to the first machine.
But it doesn't seem to work, i get "connection closed by foreign host" at the end of my script.
I hope you understand my problem. Can you please help ?
And idially, i would also like the script to enter the password automatically, if possible, but it's optionnal.

thank you very much.

Code:
$ uname -a
SunOS machinename 5.10 Generic_127111-06 sun4u sparc SUNW,Sun-Fire-V490

# 2  
Old 11-26-2009
Might be easier with the "rlogin" command?
Providing that the account name exists on both computers, "rlogin" can be configured to log in without a password.
# 3  
Old 11-26-2009
you're right it's easier.
but actually i had a problem using rlogin, it takes a long time before returning an error:

Code:
prompt $ rlogin XX.XX.XX.XX
::ffff:XX.XX.XX.XX: Connection refused
prompt $ telnet XX.XX.XX.XX
Trying XX.XX.XX.XX...
Connected to XX.XX.XX.XX.
Escape character is '^]'.

login:

but you know what, it's because i was using rlogin on the same machine, i guess that was the problem.
Thank you very much, i'm gonna switch back to "rlogin" Smilie

---------- Post updated at 02:19 PM ---------- Previous update was at 02:03 PM ----------

actually the was never the problem (rlogin to own machine)
do you know what could cause the "Connection refused" problem when using rlogin instade of telnet ?
# 4  
Old 11-26-2009
Try:
Code:
#!/bin/ksh
...
user="user"
hostname="hostname"
telnet -l $user $hostname
#end of the ksh


But to use telnet or rlogin, the remote system must be configured to allow it. rlogin is a very insecure program and most decent sys admins will prohibit it. (telnet isn't great for security either but it is better than rlogin.) If you get "connection refused" it is disabled, probably by intent.
# 5  
Old 11-30-2009
thank you for your reply.
but it still prompts me for the user and the password (i'm sure i have the "-l" option set).
i guess it is my only option Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies

2. Shell Programming and Scripting

Using Sed to do a substitution inside ksh

I'm trying to do an ls from inside of a ksh script. I loop through the results one line at a time and attempt to do a substitution using sed to convert YYYYMMDD from the older files into the newer files. Basically sometimes the ETL load runs over midnight and half the files are off by one day... (3 Replies)
Discussion started by: Calbrenar
3 Replies

3. Shell Programming and Scripting

Perl variables inside Net::Telnet::Cisco Module doesn't work

I am writing perl script to configure Cisco device but Variables inside Net::Telnet::Cisco Module doesn't work and passed to device without resolving. Please advise. here is a sample of script: use Net::Telnet::Cisco; $device = "10.14.199.1"; ($o1, $o2, $o3, $o4) = split(/\./,$device);... (5 Replies)
Discussion started by: ahmed_zaher
5 Replies

4. Shell Programming and Scripting

Using Perl Inside KSH

Hi there, I am new to Perl and KSH. The system I am using picks up the KSH scripts and uses them in a batch job control system. I am trying to set a variable from a perl command #!/bin/ksh -eaxp #******************************************************************************* # Testing... (5 Replies)
Discussion started by: SaadLive
5 Replies

5. Shell Programming and Scripting

KSH: Test telnet and exit

Hi, I need to do a test Telnet in KSH and if the connection is good then disconnect the telnet session with out logging in and without exiting the shell script. Example output of a good connection: $telnet xxx.xx.xx.xxx xxxx Trying xxx.xx.xx.xxx... Connected to xxx.xx.xx.xxx. Escape... (1 Reply)
Discussion started by: calex
1 Replies

6. Shell Programming and Scripting

Exit statement ignored inside KSH function

Hi All, I have multiple functions in my script and I'm trying to capture stdout from some of them, but I also do some error checking in them (in the functions that output something to their stdout that needs capturing) and I need to be able to end the entire script with an error message. ... (2 Replies)
Discussion started by: gkubok
2 Replies

7. Shell Programming and Scripting

expr inside a ksh script Solaris

Hi; If I do something like this. dftotalsize=0;export dftotalsize;df -k | grep \/db001 | awk '{print $4}' | while read theinput \ ; do export $theinput; dftotalsize=`expr $dftotalsize + $theinput`; export dftotalsize; echo $dftotalsize; done ; echo `expr $dftotalsize \/ 1024 \/ 1024 "GB" Is... (4 Replies)
Discussion started by: myjess
4 Replies

8. Shell Programming and Scripting

telnet with ksh

please i need to make telnet in an script but i cant use delay into the instruction because i dont know how many time takes an instruction to compleate in the other computer.How can i do? is there any form to do that?? please help sorry for my english.... (2 Replies)
Discussion started by: taboaspedro
2 Replies

9. UNIX for Advanced & Expert Users

telnet with ksh

please i need to make telnet in an script but i cant use delay into the instruction because i dont know how many time takes an instruction to compleate in the other computer.How can i do? is there any form to do that?? please help sorry for my english.... (1 Reply)
Discussion started by: taboaspedro
1 Replies

10. Shell Programming and Scripting

ksh telnet script

I am trying to write a ksh script of using telnet. On server1, I have a script that wants to telnet to server2 and run it on server2. Then after finish, brings back information to server1. Is it possible? How can I write it on ksh? Any feekback is appreciated. (5 Replies)
Discussion started by: rwunwla
5 Replies
Login or Register to Ask a Question