+ -
当前位置:首页 → 问答吧 → Net::SSH::Perl 有点问题请教高手

Net::SSH::Perl 有点问题请教高手

时间:2010-11-20

来源:互联网

perl脚本如下:
  1. #!/usr/bin/perl -w

  2. use Net::SSH::Perl;

  3. my $user = 'root';
  4. my $pass = "123456";
  5. my $host = "1.1.1.5";
  6. my $cmd = "ls";

  7. my %params = (
  8.         port => "22",
  9. );

  10. my $ssh = Net::SSH::Perl->new($host, %params);
  11. $ssh->login($user, $pass);
  12. my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
  13. print "$stdout";
复制代码
这个脚本我手动执行是没有问题的.



但是我的想写一个php页面来调用这个脚本.
我的方式是用pecl
php代码如下:
  1. <?php

  2.   $perl = new Perl();

  3.   $perl->require('exec/restart-vsftpd.pl');

  4. ?>
复制代码
在命令行执行:
manager]# php -e manager.php         
PHP Fatal error:  Uncaught exception 'PerlException' with message '[perl] require error: an attempt to getarg from a stale io handle at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 27.
Compilation failed in require at (eval 1) line 1.
' in /var/www/html/manager/manager.php:5
Stack trace:
#0 /var/www/html/manager/manager.php(5): Perl->require('exec/restart-vs...')
#1 {main}
  thrown in /var/www/html/manager/manager.php on line 5


在页面执行:apache 的error日志内容如下:
[Sat Nov 20 00:57:08 2010] [error] [client 192.168.18.234] PHP Fatal error:  Uncaught exception 'PerlException' with message '[perl] require error: an attempt to getarg from a stale io handle at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 27.\nCompilation failed in require at (eval 1) line 1.\n' in /var/www/html/manager/manager.php:5\nStack trace:\n#0 /var/www/html/manager/manager.php(5): Perl->require('exec/restart-vs...')\n#1 {main}\n  thrown in /var/www/html/manager/manager.php on line 5



不知道哪位大侠可以帮我分析下.指点指点.

作者: jasonyy77   发布时间: 2010-11-20

有没有高人可以指点下啊.

这个问题弄得我很郁闷啊.

昨晚查到凌晨4 5点都没有搞定.

作者: jasonyy77   发布时间: 2010-11-20

既然你手动执行没问题那就不应该是 perl 的问题吧?

'exec/restart-vsftpd.pl' 是不是要加上 './' 不懂 php

作者: zhlong8   发布时间: 2010-11-20

不是这个问题.因为我写了另外一个perl脚本.
使用的Net::SSH::Expect模块.可以正常执行.只是速度真不行.(页面也没有问题)

我现在怀疑是[perl] require error: an attempt to getarg from a stale io handle at /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm line 27.

这个问题.是不是 /usr/lib/perl5/site_perl/5.8.8/Net/SSH/Perl/SSH2.pm 模块有问题.
但是我的功力不够.看源代码看不太明白.

作者: jasonyy77   发布时间: 2010-11-20