免费注册 查看新帖 |

Chinaunix

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

求救:net::openssh 写了个批量脚本,执行后终端格式乱了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-12-15 17:26 |只看该作者 |倒序浏览
用net:penssh先 写了个简单批量脚本,但是跑完后当前tty格式变了(有时候正常),执行结果到result.txt是正确的,有人遇到过吗。

sub Batch_cmd {
         my $host=shift;
         chomp($host);   
         my $ssh = Net::OpenSSH->new($host,%param);
         my @out=$ssh->capture2({tty=>1},$cmd); 可能跟这个有关,应为我在sudo里设置了Defaults    requiretty,所以一般用户都是执行sudo command.
         print RES "---$host---\n";
         print RES @out;
     
$ ./run_batch.pl -l server_list -o result.txt
-----------------------------------------------------------------        
run_batch.pl v1.0
-----------------------------------------------------------------
1.run_batch.pl -u <username> -p </home/username/.ssh/id_rsa
2.run_batch.pl -l <server_list> -o <result.txt>
-----------------------------------------------------------------
You must execute Step.1 to set initial id for OPENSSH
----------------------------------------------------------------      
Please input your batch command
sudo df -h
[jimmy@zhangchl perl]$
                       cat        catchsegv  

                                             cat        catchsegv  

                                                                   cat        catchsegv  

这是结果文件

$ cat result.txt
---test01---
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                      6.5G  5.5G  658M  90% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/vda1             485M   29M  432M   7% /boot
---test02---
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                      6.5G  4.1G  2.1G  67% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/vda1             485M   29M  432M   7% /boot



论坛徽章:
0
2 [报告]
发表于 2014-12-15 17:31 |只看该作者
主要加了开线程跑加快速度,好过ssh for循环

论坛徽章:
0
3 [报告]
发表于 2014-12-15 22:07 |只看该作者
看起来是个bug
stdin没有attached to a tty,奇怪,我还是能输入但是看不到任何从终端输入,能看到混乱格式的输出

Tells ssh to allocate a pseudo-tty for the remote process. By default, a tty is allocated if remote command stdin stream is attached to a tty.

When this flag is set and stdin is not attached to a tty, the ssh master and slave processes may generate spurious warnings about failed tty operations. This is caused by a bug present in older versions of OpenSSH
有点思路了.

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP