1

Using the Net::OpenSSH module, how can I connect to a host and subsequently capture/write the output of my command to a file that has been created?

This is my command:

ps -ef | grep jboss | grep java

I have the following perl script so far..

open PATH,">","./report/archive/rpet-$now/path.txt" or die "Unable to create file: $!";
    my $ssh = Net::OpenSSH->new(
                $host,
                user=>$username
                passwd=>$password
    );
    print PATH "SSH Output Would Go Here";
close PATH;

So what is the best way to run the command and print its output? Thanks in advance!

1 Answer 1

3

Did you look at the documentation (https://metacpan.org/module/Net::OpenSSH)? It's in the synopsis.

print PATH $ssh->capture('command');

Though this will print any error conditions too. Capture works in both scalar and list context.

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried this, but it never seems to write anything to the file. Either that, or it gives me a "ssh_exchange_identification: Connection closed by remote host" error. Any ideas why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.