1

我正在用 perl 编写一个脚本,它将能够在不同的主机上并行执行多个操作。我正在使用 Net::OpenSSH 生成 ssh 会话,因为我需要能够捕获命令的输出。当我从主线程初始化 ssh 连接时,一切正常,但以下脚本返回以下错误:

无法建立 SSH 连接:无法建立主 SSH 连接:控制命令失败:子进程 8392 不存在:没有子进程

有谁知道如何解决这个问题?

提前谢谢了!

  our $threads{'1'} = {
    'thread' => '0',
    'ssh' => '0'
  };

  threadsInitialization();

  sub threadsInitialization{
        $threads{'1'}->{'thread'} = threads->create(sub {script();});
        $threads{'1'}->{'thread'}->join();
  }

  sub script{
        print("Test action will be executed now...\n");
        $threads{'1'}->{'ssh'}=sshInit(<host>,<user>,<passwd>); #<- error

        #execute some actions

  }

  sub sshInit{
        my ($host, $user, $passwd) = @_ or die "No arguments were supplied";
        print("Establishing ssh connection to $host as $user...\n");
        my $ssh = Net::OpenSSH->new("$host", user => "$user", passwd => "$passwd",         master_opts => [-o => "StrictHostKeyChecking=no"], timeout => 600);
        $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error;
        print("ssh connection to $host as $user established successfully.");
        return $ssh;
  }
4

0 回答 0