标签:style blog color 使用 strong 数据 io 2014
--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 27 19:31:18 2014 from 10.181.225.39
Welcome to tlinux 1.2 64bit
Version 1.2 20130715
[root@TENCENT64 ~]# 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;"
??-SNG-???? 26061 10.236.158.100:3951 宅计划 1251002789
[root@TENCENT64 ~]# sleep 1
exit
[root@TENCENT64 ~]# exit
logout
可见这句话在传过去的时候就是乱码了,不是返回时的乱码。
使用strace跟踪脚本的执行,发现如下编码相关语句:
open("/usr/lib/locale/en_US/LC_CTYPE", O_RDONLY) = 3
查看本机locale:
# locale
LANG=en_US.UTF-8
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 27 19:26:49 2014 from 10.181.225.39
Welcome to tlinux 1.2 64bit
Version 1.2 20130715
at(tvs_vip,‘:‘,tvs_vport),instance_name,app_name from tb_mysql_pair where sync_status=1 and tvs_vport<>0 and status=3;" 外部-SNG-上海松江‘,pair_id,conc
外部-SNG-上海松江 26061 10.236.158.100:3951 宅计划 1251002789
[root@TENCENT64 ~]# sleep 1
exit
[root@TENCENT64 ~]# exit
logout
Strace跟踪解决expect乱码问题,布布扣,bubuko.com
标签:style blog color 使用 strong 数据 io 2014
原文地址:http://www.cnblogs.com/jackhub/p/3871790.html