expect is not working for non-English language

Viewed 67

I am doing Postgres database auto backup on CentOS 7.9 using expect and shell code. My code is working fine in English environment but it fails in Japanese environment. Here is my expect code

#!/usr/bin/expect
set homeDirectory "/home/kds/DB_BACKUP"
set dbPassword "manager"

log_file $homeDirectory/LOG/db_backup.log;

#Execute database backup script

spawn $homeDirectory/./backupexecutor.sh

set found 0
while {$found < 1} {
expect {
"パスワード: $"    {send "$dbPassword\r"}
"^Rollout Done "   {set found 1}
"^Rollout Updated " {set found 1}
}
}

expect eof

After checking the log file it is clear that expect cannot send password for パスワード: $ keyword. I also tried *スワー* but same result. If change my OS language from Japanese to English and replace パスワード to Password the code works fine. Is there any way to work expect with a different language?

1 Answers

Did a simple test and it worked for me (tested with Expect 5.45, Tcl 8.5.9, macOS 10.15).

[STEP 101] $ cat foo.sh
read -s -p 'Enter your パスワード: ' passwd
echo
echo "Your password is: $passwd"
[STEP 102] $ bash foo.sh
Enter your パスワード: foobar  <-- manual input
Your password is: foobar
[STEP 103] $
[STEP 104] $ cat foo.exp
spawn bash foo.sh
expect {
    "パスワード: $" {
        send "foobar\r"
    }
}
expect eof
[STEP 105] $ expect foo.exp
spawn bash foo.sh
Enter your パスワード:
Your password is: foobar
[STEP 106] $

My locale info:

[STEP 107] $ locale
LANG=""
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
[STEP 108] $

expect -d:

[STEP 109] $ expect -d foo.exp
expect version 5.45
argv[0] = expect  argv[1] = -d  argv[2] = foo.exp
set argc 0
set argv0 "foo.exp"
set argv ""
executing commands from command file foo.exp
spawn bash foo.sh
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {84009}

expect: does "" (spawn_id exp6) match glob pattern "\u30d1\u30b9\u30ef\u30fc\u30c9: $"? no
Enter your パスワード:
expect: does "Enter your \u30d1\u30b9\u30ef\u30fc\u30c9: " (spawn_id exp6) match glob pattern "\u30d1\u30b9\u30ef\u30fc\u30c9: $"? yes
expect: set expect_out(0,string) "\u30d1\u30b9\u30ef\u30fc\u30c9: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Enter your \u30d1\u30b9\u30ef\u30fc\u30c9: "
send: sending "foobar\r" to { exp6 }

Your password is: foobar
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r\nYour password is: foobar\r\n"
[STEP 110] $
Related