Thursday, 15 July 2010

Escape Password variable in expect script -



Escape Password variable in expect script -

background: trying write expect script used testing special character passwords. 1 of test cases failing execute having special character "-" in front end of password. illustration : "-foo" note: assume ssh key out of question note: assume bash shell shell using

my code: connect function, courtesy of wikipedia:

proc connect {passwd} { expect { "yes/no" { send "yes\r" } } expect { "?assword:" { send "$passwd\r" expect { "sftp*" { homecoming 0 } } } } # timed out homecoming 1 } set user [lindex $argv 0] set passwd [lindex $argv 1] set host [lindex $argv 2] spawn sftp $user@$host puts '$passwd'\r set rez [connect $passwd]

within bash script have:

passwd="-foo" ./sftp_test $user $passwd $host

what have tried: understand issue shell expanding variable , command beingness interpreted send -foo @ says send has invalid password.

i have tried using single quotes general solution password beingness rejected (i suspect single quotes beingness preserved). send '$passwd'"\r"

the question: there way me escape password in send command can utilize permutations of special characters in password (e.g. $foo , f$oo , -foo)?

what need this:

send -- "$passwd\r"

the -- indicates next words origin dash not treated alternative send command.

you might want create habit , every send command.

expect

No comments:

Post a Comment