Special Character issue in Expect Utility (Tcl)

Hi,

I have written a unix expect utility "ssh-login.exp" which connects (ssh) to remote host and execute some shell script. I am calling this "ssh-login.exp" utility from another shell script.

"ssh-login.exp" takes username, password, host and shell script path to execute on remote host. All works fine for alphanumeric passwords. If password contains special characters e.g. "$", "ssh-login.exp" doesn't work. I have already added logic to add escape character right before any special characters in password string.

e.g. for password string "welcome$123" and I send "welcome\$123".

The issue is when expect utility "ssh-login.exp" sends password to remote host, it prepends '{' and appends '}' to password string if password contains any special characters. if password doesn't have any special characters then it sends password without '{' and '}' and works fine.

e.g. for password "welcome$123" expect program sends "{welcome\$123}", in fact it should send "welcome\$123" (without '{' and '}' ). If password is "{welcome\$123}" remote machine don't allow the entry because of wrong password as it is '{' and '}'.

So I am trying to find out a way to get rid of '{' and '}' from password string before sending it to remote host if password contains any special characters.

Here is my expect script : "ssh-login.exp":

#!/usr/bin/expect -f

set username [lrange $argv 0 0]
set password [lrange $argv 1 1]
set host [lrange $argv 2 2]
set script [lrange $argv 3 3]

set prompt "*$*"

set scriptIO  [open ./$script r]
set scriptContents [read -nonewline $scriptIO]
close $scriptIO

spawn ssh -q -o StrictHostKeyChecking=no $username@$host

#match_max 100000

while (1) {
        expect {
                "no)? " {
                        send -- "yes\r"
                        send -- "\r"
                }
                "*?assword:*" {
                        send -- "$password\r"
                        send -- "\r"
                }
                "$prompt" {
                        send -- "pwd\r"
                        send -- "\r"
                        break;
                }
        }
}

send -- "\r"

send -- "$scriptContents\r"

send -- "exit\r"

expect eof

Please let me know if someone has already faced this issue and were able to resolve it.

Thanks,

Try:

send -- "[join $password]\r"

or

set password [join [lrange $argv 1 1]]