[ale] RESOLVED Re: [OT] expect script question

Robert Heaven roberth1954 at aim.com
Thu Apr 5 23:52:37 EDT 2012


Found it...

I needed to use the tcl "glob" command combined with a "foreach"...

#!/usr/local/bin/expect --
set timeout 1200
spawn ssh myhostname
expect "> "
set dir "tmp"
set list [glob -directory $dir tempfile*]
foreach file $list{
	send "chmod 664 $file\r"
	expect "> "
	send "mv $file $file.moved\r"
	expect "> "
}


On Apr 5, 2012, at 7:41 PM, Robert Heaven wrote:

> I need to write an expect script to ssh to a host, do a cd to a dir, do an ls to list some file and then do chmod on certain files. I know that executing the "cd" and "ls" commands would use a simple "send" but, how do I capture the output of the "ls" and how do I loop through the list so that I can "send" the chmod command. I know how to do all these things in bash and perl, I'm just not familiar with tcl/tk.
> 
> -Robert
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo




More information about the Ale mailing list