I want to SSH to a server and execute a simple command like \"id\" and get the output of it and store it to a file on my primary server. I do not have privileges to install
I had a similar issue, and after much searching I've found a simple option. I used qx()
and ran the ssh commands like I normally would. The catch is I had to capture both stderr and stdout.
The following is an example of what I used:
my $output = qx(ssh root\@$curIP python -V 2>&1);
It runs the python -V
command, which outputs the version info to stderr
. In this example, my ip address was stored in the $curIP
variable. Lastly, the 2>&1
helps capture both stdout and stderr. I did not specify a password, as I have key exchanges setup. Hope this helps.