LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-17-2008, 09:56 AM   #1
gustavolinux
Member
 
Registered: Aug 2008
Posts: 36

Rep: Reputation: 15
Lightbulb TCL e EXPECT


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@172.21.1.99 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@172.21.1.99 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
 
Old 10-17-2008, 10:03 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,270

Rep: Reputation: 99
hope this helps.

Hey,

I am no expert, but you could find this useful.
Code:
#!/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
Usage
Code:
./script.sh password IP cmd
Hope this helps.

Regards,
VIKAS
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
expect (Tcl) question kristof_v Programming 2 01-24-2013 06:32 AM
tcl/expect telnet spawns randomly close Hewson Programming 1 05-12-2007 11:25 AM
TCL/expect - parent hangs when child dies Hewson Programming 1 03-27-2007 09:44 PM
Installation of Expect 5.x tcl private headers Anarchon Linux - Software 0 07-08-2005 10:02 AM
TCL, Expect, for Rsync - Please Help dholingw Programming 2 02-08-2004 11:27 AM


All times are GMT -5. The time now is 04:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration