免费注册 查看新帖 |

Chinaunix

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

关于Net::SSH::Perl又一问题(已经解决) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-10 16:25 |只看该作者 |倒序浏览
我想把得到ssh句柄的功能写成一个函数,可是为什么不行呢?Net::SSH:erl这个模块还不是很熟悉啊!

85 sub get_ssh {
 86    my $remote_ip = shift;
 87    my $user = shift;
 88    my $password = shift;
 89    my %params = (
 90        protocol => '2',
 91        debug => '0',
 92        privileged => '0',
 93      );
 94   print "connect to $remote_ip \n";
 95   my $host = $remote_ip;
 96   my $ssh = Net::SSH::Perl->new($host,%params);
 97   return $ssh;
 98 }


  9 my $remote_h = get_ssh("172.16.1.46","root","123456");
 10 my ($stdout,$stderr,$exit) = $remote_h->cmd("hostname");
 11 if($exit){
 12   print "error: $stderr\n";
 13 }else{
 14   print "$stdout\n";
 15 }


[ 本帖最后由 justlooks 于 2009-11-10 16:50 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-11-10 16:28 |只看该作者

回复 #1 justlooks 的帖子

目标请直接return啦~~
不必加引用~~

论坛徽章:
0
3 [报告]
发表于 2009-11-10 16:40 |只看该作者
原帖由 兰花仙子 于 2009-11-10 16:28 发表
目标请直接return啦~~
不必加引用~~


我直接返回但是还是有问题阿,正确的话应该显示机器名字啊

Subroutine check_time redefined at do_query_test line 45.
defined(@array) is deprecated at do_query_test line 132.
        (Maybe you should just omit the defined()?)
connect to 172.16.1.46
hch: Reading configuration data /root/.ssh/config
hch: Reading configuration data /etc/ssh_config
hch: Connecting to 172.16.1.46, port 22.
hch: Remote protocol version 2.0, remote software version OpenSSH_4.3
hch: Net::SSH:erl Version 1.34, protocol version 2.0.
hch: No compat match: OpenSSH_4.3.
hch: Connection established.
===Net::SSH:erl::SSH2=HASH(0x838cb44)    这个是函数里的$ssh
))))Net::SSH:erl::SSH2=HASH(0x838cb44)   这个是取到的
hch: channel 0: new [client-session]
hch: Requesting channel_open for channel 0.
hch: Entering interactive session.
Use of uninitialized value in concatenation (.) or string at do_query_test line 16, <GEN0> line 1.

论坛徽章:
0
4 [报告]
发表于 2009-11-10 16:44 |只看该作者
re-check it~~
你哪里用到username和password了~~

论坛徽章:
0
5 [报告]
发表于 2009-11-10 16:49 |只看该作者
原帖由 兰花仙子 于 2009-11-10 16:44 发表
re-check it~~
你哪里用到username和password了~~


汗CP漏了代码,OK了

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
6 [报告]
发表于 2009-11-10 16:55 |只看该作者
这个模块还是比较有用的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP