免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4258 | 回复: 4
打印 上一主题 下一主题

Net::SSH::Expect远程执行ls -l命令的疑惑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-10-21 21:04 |只看该作者 |倒序浏览
最近使用Net::SSH::Expect在远程主机上获取设备信息;出现了一个很奇怪的状况:
远程执行命令:$ssh->exec("ls -l /etc/passwd",得到的结果出现了乱码;
但是执行其他的非ls命令,如cat /etc/ntp.conf等,都不会出现乱码,这是什么原因?折腾了一天,没有头绪,有人能帮忙瞅瞅么?

命令执行的部分结果截取:
cmd ===ls -l /etc/passwd 2>err.txt;;;;;type=1
value ===←-rw-r--r-- 1 root root 2080 Jul 28 20:35 ←[00m/etc/passwd←

cmd ===cat /etc/sysctl.conf|grep net.ipv4.conf.all.accept_redirects |grep ^[^#] 2>err.txt;;;;;type=1
value ===net.ipv4.conf.all.accept_redirects=0

cmd ===cat /etc/ntp.conf|grep ^[^#] | grep -i server 2>err.txt;;;;;type=1
value ===server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server        127.127.1.0        # local clock

cmd ===cat /etc/passwd /etc/login.defs |grep ^[^#] 2>err.txt;;;;;type=1
value ===root:0:0:root:/root:/bin/bash
bin:1:1:bin:/bin:/sbin/nologin
daemon:2:2:daemon:/sbin:/sbin/nologin

论坛徽章:
1
综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00
2 [报告]
发表于 2013-10-22 06:35 |只看该作者
执行$ssh->exec("cat /etc/passwd")呢?

论坛徽章:
0
3 [报告]
发表于 2013-10-22 08:53 |只看该作者
执行cat命令没有问题

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2013-10-22 09:18 |只看该作者
用这个命令就没事了
“ls -l /etc/passwd | cat”

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
5 [报告]
发表于 2013-10-22 11:59 |只看该作者
本帖最后由 jason680 于 2013-10-22 12:01 编辑

回复 1# jinwh12

try this one without color

ls -l --color=none /etc/passwd
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP