Strace跟踪解决expect乱码问题

--Strace跟踪解决expect乱码问题

----------------------------------2014/07/27

情景:需要在本机抓去另外一台远程数据库中的数据。

执行语句:./ersh.exp "export LANG=en_US.UTF-8;mysql -uroot  -S /tmp/mysql_3306.sock -ss  cdb2 -e \"set names utf8; select '外部-SNG-上海松江',pair_id,concat(tvs_vip,':',tvs_vport),instance_name,app_name from tb_mysql_pair where sync_status=1 and tvs_vport<>0 and status=3;\""  10.237.152.19

输出结果:

spawn ssh -p36000 10.237.152.19 -lroot -q
root's password:
Last login: Sun Jul :: from 10.181.225.39
Welcome to tlinux 1.2 64bit
Version 1.2
[root@TENCENT64 ~]# export LANG=en_US.UTF-;mysql -uroot -S /tmp/mysql_3306.sock -ss cdb2 -e "set names utf8; select '??-SNG-????',pair_id,concat(tvs_vip,':',tvs_vport),instance_name,app_name from tb_mysql_pair where sync_status=1 and tvs_vport<>0 and status=3;"
??-SNG-???? 10.236.158.100: 宅计划
[root@TENCENT64 ~]# sleep
exit
[root@TENCENT64 ~]# exit
logout

可见这句话在传过去的时候就是乱码了,不是返回时的乱码。

使用strace跟踪脚本的执行,发现如下编码相关语句:

open("/usr/lib/locale/en_US/LC_CTYPE", O_RDONLY) = 3

查看本机locale:

# locale
LANG=en_US.UTF-
LC_CTYPE=en_US
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

猜测是LC_CTYPE的设定问题引起此语句传输到其他机器时发生乱码,将LC_CTYPE设置成en_US.UTF-8,问题解决。

./ersh.exp "export LANG=en_US.UTF-8;mysql -uroot -S /tmp/mysql_3306.sock -ss cdb2 -e \"set names utf8; select '外部-SNG-上海松江',pair_id,concat(tvs_vip,':',tvs_vport),instance_name,app_name from tb_mysql_pair where sync_status=1 and tvs_vport<>0 and status=3;\"" 10.237.152.19
spawn ssh -p36000 10.237.152.19 -lroot -q
root's password:
Last login: Sun Jul :: from 10.181.225.39
Welcome to tlinux 1.2 64bit
Version 1.2
at(tvs_vip,':',tvs_vport),instance_name,app_name from tb_mysql_pair where sync_status= and tvs_vport<> and status=;" 外部-SNG-上海松江',pair_id,conc
外部-SNG-上海松江 10.236.158.100: 宅计划
[root@TENCENT64 ~]# sleep
exit
[root@TENCENT64 ~]# exit
logout
上一篇:【转载】S2SH


下一篇:Mastering Web Application Development with AngularJS 读书笔记(二)