expect is not working for different language

Issues related to applications and software problems
Post Reply
tuski
Posts: 5
Joined: 2020/12/22 04:43:54

expect is not working for different language

Post by tuski » 2020/12/26 06:03:15

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

Code: Select all

#!/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?

pjsr2
Posts: 548
Joined: 2014/03/27 20:11:07

Re: expect is not working for different language

Post by pjsr2 » 2020/12/29 21:36:35

it is clear that expect cannot send password for "パスワード: $" keyword
Expect does not send パスワード, it expects that the database server sends the string パスワード and when expect reads that string, is sends the password in $dbPassword. So if you change the language for the user that runs the expect script to Japanese, the database should also reply in Japanese. Is that the case?

I assume that your run expect on a CentOS machine, which uses UTF-8 encoding. Is your database server also Linux, or is it Windows based? If Windows, it will send the パスワード string in SHIFT-JIS encoding, which will not match with the UTF-8 encoding that expect uses. The character enconding of "Password" is the same in SHIFT-JIS and UTF-8, so that will match.

Post Reply

Return to “CentOS 7 - Software Support”