ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> expect
expect
[Expect] Scripting SSH with Activestate Expect and TCL...'?' chars inserted in terminal
by asilver other posts by this author
Jun 27 2008 8:12AM messages near this date
view in the new Beta List Site
Re: [Expect] Expect on windows is not working!!!! | Re: [Expect] Scripting SSH with Activestate Expect and TCL...'?' chars inserted in terminal
I saw this on the google TCL group because I am experiencing the same
exact problem.  Thought it was a good idea to post here as well:


I'm experiencing the same exact problem sending to a Cisco router.  I'm
also using plink.  The character "?" only occasionally gets inserted out
of nowhere??  I've tried experimenting with the Expect send_slow variable
(send_block and send_delay) with a little bit of improvement but this
problem still creeps up. I've never seen this happen when using telnet,
only ssh.  Was there ever a resolution to this issue??

Thanks
Al

ccly...@[...].com wrote:
>  I'm new to tcl, expect, and coding from a windows environment ;)  I am
>  using ctivestates distribution of Expect and TCL on a Windows XP host
>  with PuTTY's Plink tool, attempting to connect to Sun Solaris boxes
>  using openssh.  My goal here is very simple:  I want to automate
>  sshing to a list of IPs, and execute the same series of commands on
>  each machine.  Some of these commands require sudo, so I have to pass
>  a password to that as well.
> 
>  I have the script below working to read through the list of IPs and
>  login to each one.  I have it passing the password to sudo properly.
>  However, I'm getting some weirdness with the output.  It should be
>  passing something like:
> 
>  sh -c 'echo \"HISTORY=5\" >> /etc/default/passwd'
> 
>  However it keeps inserting ? characters, so what I get is more like:
> 
>  sh -c 'echo \"HISTORY=5\" >> /etc/default/p?asswd'
> 
>  I suspect my issue has to do with some fundamental misunderstanding on
>  my part about how to deal with spawning processes and subprocesses in
>  TCL/Expect.  Please help if you can...what I want SEEMS like it should
>  be so trivial, yet I'm completely hung up here.
> 
>  #!/bin/sh
>  # >       exec tclsh "$0"  ${1+"$@"}
> 
>  package require Expect
> 
>  # Turn off echo logging to the user by default exp_log_user 1
>  exp_internal 1
> 
>  # This is the magic timeout variable used by Expect (time in seconds).
>  set timeout 10
> 
>  # We want to operate very simply - force a dumb terminal mode set
>  env(TERM) dumb
> 
>  set ::exp::winnt_debug 1
> 
>  set timestamp [clock format [clock seconds]] set ip [open ips.txt] set
>  exp_log_file login.log
> 
>  # The default option settings
>  array set OPTS {
>      user    "MYUSER"
>      password  "MYPASS"
>      prompt  "(%|#|>|\\$) $"
>      command "sudo chmod 777 /etc/default/passwd"
>  }
> 
>  while {[gets $ip line] >=0 } {
>  	set pid [spawn Plink.exe $line -l $OPTS(user) -pw $OPTS(password)]
>  	set id $spawn_id
>  	set logged_in 0
>  	while {!$logged_in} {
>  		# Handle  SSH host key dialog
>  		expect -re "(\[Yy\]es\/\[Nn\]o).*" {
>   		   	exp_send "yes\r"
>  		}
>  		expect -re "(\[Yy\]\/\[Nn\]).*" {
>  		    	exp_send "y\r"
>  		}
>  		expect -re $OPTS(prompt) {
>  			set logged_in 1
>  		}
>  	}
> 
>  	if {$logged_in} {
>  #		expect -re $OPTS(prompt)
>  		# Run command with sudo
>  		exp_send "$OPTS(command)\r"
>  		expect -re "\[Pp\]assword:\r"
>  		exp_send "$OPTS(password)\r"
>  		exp_send "sh -c 'echo \"HISTORY=5\" >> /etc/default/passwd'\r"
>  		exp_send "sudo chmod 444 /etc/default/passwd\r"
>  		expect -re "\[Pp\]assword:\r"
>  		exp_send "$OPTS(password)\r"
>  		exp_send "tail /etc/default/passwd\r"
>  	}
>  	exp_close -i $id
>  	exp_wait -i $id
>  }

_______________________________________________
Expect mailing list
Expect@[...].com
http://listserv.ActiveState.com/mailman/listinfo/expect
Thread:
asilver
Jeff Hobbs
asilver

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved