Anyone with an expect question?

Steven W. Orr steveo at syslang.net
Tue Oct 11 14:13:16 EDT 2011


I get lucky here sometimes.

I have a script I use to su to different accounts. It has all the passwords 
and yes, for what I'm doing, it's ok. This is not a security question.

Here's the issue. From a winbloze box via putty or from a native xterm (it 
doesn't matter), I run stty -a to see the rows and columns. All is right with 
the world. If I did not use the script to su - to another account and I change 
the size of the window, the size is properly updated. BUT! If I go through the 
script and change the window size, the size is not updated.

I looked through the expect docs for interact and spawn, but I didn't see 
anything interesting.

Any expectations of wizardry? ;-)

#!/usr/bin/expect -f

set timeout -1
set user [lrange $argv 0 0]
set cmd [lrange $argv 1 end]

switch $user {
     "root" {
         set password "xxx"
     }
     "hoohaw" {
         set password "yyy"
     }
     default {
         puts stderr "No password supplied for user $user"
         exit 1
     }
}

if { [llength $cmd] == 0 } {
     spawn -noecho su - $user
} else {
     eval {spawn -noecho su - $user -c} $cmd
}
log_user 0
expect "^Password: $" {
     send "$password\r"
     expect "\r\n"
     log_user 1
}
interact


-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


More information about the gnhlug-discuss mailing list