Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

telnet to a unix server using tcl scripts

304 views
Skip to first unread message

Ravikanth

unread,
Jul 12, 2008, 6:51:11 AM7/12/08
to avem...@alcatel-lucent.com
Hi all,

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

Cameron Laird

unread,
Jul 12, 2008, 9:13:16 AM7/12/08
to
In article <8952a6fb-e509-4a5c...@e39g2000hsf.googlegroups.com>,
.
.
.
I'm well into my second decade of use of Tcl and Expect.
My expertise is not yet great enough, though, even to
consider attempting what you're after with sleeps,
rather than Expect, unless I were guaranteed $5000 up-
front to cover all the difficulties I anticipate.

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?

r_ha...@gmx.de

unread,
Jul 12, 2008, 2:10:08 PM7/12/08
to

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.

Glenn Jackman

unread,
Jul 13, 2008, 7:51:18 AM7/13/08
to
At 2008-07-12 06:51AM, "Ravikanth" wrote:
> #!/usr/add-on/exptools/bin/tclsh
> set fd [open "|telnet <unix server>" r+]
[...]

> My aim is to login to the server and confirm it by typing the
> 'hostname' command and reading back and confirming 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

des...@gmail.com

unread,
Jul 14, 2008, 7:33:12 PM7/14/08
to

Please give a try to TclCurl. see following link
<http://personal1.iddeo.es/andresgarci/tclcurl/english/>.

HTH
Dinakar Desai

0 new messages