-   Programming (
-   -   TCL e EXPECT (

gustavolinux 10-17-2008 08:56 AM

Hi folks, could any tcl and expect programmer help me please?

I'm making a tcl script that just executes one command using ssh, without the need of typing a password manually (tcl sends the password).

I did the 'expect' and 'send' part of the script easily. It waits for the ssh response, sends the correct password and fine. But I don't know how to make the command (the one sent by ssh) display its results on the screen. I need help for this, please.

The segment of the script where I don't know what to do is this:


package require Expect;

spawn ssh root@ ls

expect "Password: "

send "123\r"



As I said, when I execute it (test.tcl), what happens is that the results are not displayed..


root@linuxbermudas:/home/root# tclsh ./test.tcl
spawn ssh root@ ls
Password: root@linuxbermudas:/home/root#


The directory list should be displayed... :(

What I need to do to allow 'ls' to display its results?

thanx in advance

vikas027 10-17-2008 09:03 AM

hope this helps.

I am no expert, but you could find this useful.

#!/usr/bin/expect -f
# set Variables
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 2]
set arg1 [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh root@$ipaddr $scriptname $arg1
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof


./ password IP cmd
Hope this helps.


All times are GMT -5. The time now is 12:09 PM.