- 论坛徽章:
- 0
|
最近学习线程,编写测试程序manage.pl,利用线程访问srv.list中的服务器,取得uname -a 的值,但是提示
Thread 1 terminated abnormally: Not a CODE reference at manage.pl line 17.
另外如果列表中某台服务器不能访问,程序会中断
并提示
Permission denied at manage.pl line 35
Perl exited with active threads:
0 running and unjoined
6 finished and unjoined
0 running and detached- #!/usr/bin/perl
- use strict;
- use Net::SSH::Perl;
- use threads;
- use Thread::Queue;
- my $queue = new Thread::Queue;
- my $max = 10;
- open my $IN, '<', 'srv.list' or die "Don't open File!\n";
- while (<$IN>)
- {
- $queue->enqueue($_);
- }
- close $IN;
- for ( my $n = 0; $n < $max; $n++)
- {
- threads->create(\&exec_command());
- }
- foreach my $th (threads->list(threads::all))
- {
- $th->detach();
- }
- sub exec_command()
- {
- my $host = $queue->dequeue();
- my $user = 'zoomi';
- my $pass = 'zoomi-init';
- my $cmd='uname -a';
- my $ssh = Net::SSH::Perl->new($host);
- $ssh->login($user, $pass);
- my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
- if ($exit == 0) {
- print "$host -> $stdout";
- } else {
- print "$host -> $stderr";
- }
- }
复制代码- 10.60.30.15
- -> Linux zoomi-30-15 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
- Thread 1 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.16
- -> Linux zoomi-30-16 2.6.31-23-server #74-Ubuntu SMP Mon Feb 28 22:32:34 UTC 2011 x86_64 GNU/Linux
- Thread 2 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.17
- -> Linux zoomi-30-17 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
- Thread 3 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.18
- -> Linux zoomi-30-18 2.6.31-14-server #48-Ubuntu SMP Fri Oct 16 15:07:34 UTC 2009 x86_64 GNU/Linux
- Thread 4 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.19
- -> Linux ubuntu 2.6.31-14-server #48-Ubuntu SMP Fri Oct 16 15:07:34 UTC 2009 x86_64 GNU/Linux
- Thread 5 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.25
- -> Linux zoomi-30-25 2.6.31-14-server #48-Ubuntu SMP Fri Oct 16 15:07:34 UTC 2009 x86_64 GNU/Linux
- Thread 6 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.27
- -> Linux server-A-test 2.6.31-14-server #48-Ubuntu SMP Fri Oct 16 15:07:34 UTC 2009 x86_64 GNU/Linux
- Thread 7 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.28
- -> Linux zoomi-30-28 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
- Thread 8 terminated abnormally: Not a CODE reference at manage.pl line 17.
- 10.60.30.29
- -> Linux server-B-test 2.6.31-14-server #48-Ubuntu SMP Fri Oct 16 15:07:34 UTC 2009 x86_64 GNU/Linux
- Thread 9 terminated abnormally: Not a CODE reference at manage.pl line 17.
复制代码 |
|