{ # forking plugin to run a command on a remote server via ssh # non interactive and buffered. output returns after command completes binmode(STDOUT); # Required for this to work on MSWin32 my $cmd = shift; my $nick = shift; my $who = shift; my $where = shift; my $channel=shift; my $args=shift; my $msg=shift; my %hash = %$args; my $data; my $filter = POE::Filter::Reference->new(); my $cmdargs=""; my ($plugin, $user, $pass, $host, $cmdx, @args)=split /\s+/, $msg; # print "nick[$nick] who[$who]\n"; # print "got ($plugin, $user, $pass, $host, $cmdx, @args)\n"; for my $arg (@args){ $cmdargs .= " " . $arg; } use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new($host, options => [ "BatchMode yes", "RhostsAuthentication no", "Debug true" ]); $ssh->login($user, $pass); my ($stdout, $stderr, $exit) = $ssh->cmd($cmdx, $cmdargs); chomp($stdout);chomp($stderr); # remove (translate) non-printable chrs $exit =~ tr/\x80-\xFF//d; $stderr =~ tr/\x80-\xFF//d; $stdout =~ tr/\x80-\xFF//d; my $status = "exit[$exit] stderr[$stderr] stdout[$stdout]\n"; my $result = $status; # Code Goes Above # # return results print "task[$cmd] status[$status] reply_to[$nick] Result[$result]\n"; my %result = ( task => $cmd, status => $status, reply_to => $nick, result => $result ); my $output = $filter->put( [ \%result ] ); print @$output; }