I have a doubt regarding telnet to a UNIX server using a tcl script
I have written the following code
#!/usr/add-on/exptools/bin/tclsh
set fd [open "|telnet <unix server>" r+]
puts "Calling 1st sleep..."
exec sleep 3
puts "After 1st sleep for 3 seconds..."
set first [read -nonewline $fd]
puts "Sending login name....."
puts $fd "ravikanv"
flush $fd
exec sleep 2
gets $fd
puts "sending password....."
puts $fd "xxxxxxxx"
exec sleep 6
set startinfo [read $fd]
puts $fd "hostname"
flush $fd
gets $fd hostinfo
puts "The current host is :$hostinfo"
The aim my code is to login to a UNIX server using a tcl script.
I should have used expect here but the time delays given were
sufficent enough as i have checked login to the server directly from
the command line so the delays were ample.
When i run the script,
the output is as follows...
---------------------------------------------------
Calling 1st sleep...
After 1st sleep for 3 seconds...
...................................................
and after that nothing is coming up on the screen.
My aim is to login to the server and confirm it by typing the
'hostname' command and reading back and confirming it..
but nothing is coming up as you see in the output.
Please help me in clarifying this.
Thanks in advance,
Ravikanth
I'll say that a different way: I've used sleep-based
login automations. I hope never again to do so in this
lifetime.
Are there any words that will more effectively communicate
that my advice to you is to reconsider your rejection of
Expect?
Incidentally,
after 3000
is a more idiomatic way to write
exec sleep 3,
and unencrypted telnet passwords are generally seen as
silly in 2008, and it seems strange to me to mix [read]
and [gets] as you're doing, and ...
Do you realize the fragment above appears not to [flush]
after sending the password?
Hello Ravikanth,
did you consider using the tcltelnet package from http://tmartin.org/tcltelnet/.
I have just recently come across this package but not yet used it.
I'll add my encouragment to try a different approach. If you just want
to execute simple commands on a remote host, look into ssh:
ssh -l username remote_server hostname
You will want to set up a passphrase-less key pair between your current
host and the remote host so that you don't have to enter a password (if
that's important for you).
If you require more interaction on the remote host, Expect is certainly
the way to go.
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Please give a try to TclCurl. see following link
<http://personal1.iddeo.es/andresgarci/tclcurl/english/>.
HTH
Dinakar Desai