zabbix_server执行window脚本出现中文乱码如何解
2020-04-09 本文已影响0人
乐维_lwops
场景分析:
1. A企业员工啊旺在zabbix_server上,执行了一个通过agent调用远程window主机脚本的操作,但是由于该脚本的输出结果带有中文,啊旺在zabbix_server的界面看到的内容是一串乱码字符,他根本不知道远程脚本是否执行成功。于是他想把脚本的输出结果改成英文提示success或者error。但由于该脚本不是由啊旺编写的。所以他不知道应该修改脚本的那个位置,才能使显示为英文。因此,本文的目的就是为了解决,zabbix_server调用window的远程脚本带有中文的显示乱码问题。
第一步:编写一个window上输出中文的bat脚本

在window服务器上执行bat脚本是否可以输出结果

Window主机上执行bat脚本,结果正常输出。
第二步:在zabbix_server上创键执行该文件的脚本

因为该脚本是window上的脚本,所以要选择执行在zabbix客户端

在脚本存放的主机上执行该脚本


执行后的结果,如下图,中文显示乱码,数字显示正常(英文也显示正常)

第三步:编写转码的bat脚本实现,中文的正常输出
文件的路径要用绝对值,否则调用的时候会出现报错

第一行:把test.bat脚本执行结果的内容输出到1.txt文件
第二行,把test.txt这个文件转码为utf8的格式
(注意,第二行,源文件名不能和转码后的名字一样,否则会使转码后的文件为空)
即不能使用powershell -c "Get-Content F:\桌面C盘\1.txt|Out-File -Encoding utf8 F:\桌面C盘\1.txt"
第三行是查看test.bat脚本执行的就够
第四,五行删除刚才生成的文件
重新修改执行window脚本


Ok,大功告成。中文显示正常
技术交流欢迎加入Q群:177428068