IPC::PerlSSH::Library::Run - a library of command running functions for IPC::PerlSSH
IPC::PerlSSH::Library::Run
IPC::PerlSSH
use IPC::PerlSSH; my $ips = IPC::PerlSSH->new( Host => "over.there" ); $ips->use_library( "Run", qw( system system_out system_in ) ); my ( $result, $out ) = $ips->call( "system_out", qw( ip addr ls ) ); $out == 0 or die "ip failed\n"; for (split m/\n/, $out ) { # some processing here... } my $result = $ips->call( "system", qw( ip addr add 1.2.3.4/28 dev eth0 ) ); # To execute a shell command, send a single string my $result = $ips->call( "system_in", "1", "echo >/proc/sys/net/ipv4/ip_forward" );
This module provides a library of functions for executing processes on the remote system. As well as a basic system()-like wrapper, there are also functions for passing data in to the executed process's STDIN stream, reading from its STDOUT stream, or both simultaneously.
system()
Each of these functions will only return once the remote process has exited. If interaction with the process is required while it is running, a remote pipe open may be performed instead using functions in IPC::PerlSSH::Library::IO.
The following four functions do not redirect the STDERR stream of the invoked program, allowing it to pass unhindered back through the ssh connection to the local program.
STDERR
Execute a program with the given arguments, returning its exit status.
my $exitstatus = $ips->call( "system", $path, @args );
To obtain the exit value, use WEXITSTATUS from POSIX.
WEXITSTATUS
POSIX
Execute a program with the given arguments, passing in a string to its STDIN, and returning its exit status
my $exitstatus = $ips->call( "system_in", $stdin, $path, @args );
Execute a program with the given arguments, returning its exit status and what it wrote on STDOUT.
my ( $exitstatus, $stdout ) = $ips->call( "system_out", $path, @args );
Execute a program with the given arguments, passing in a string to its STDIN, and returning its exit status and what it wrote on STDOUT.
my ( $exitstatus, $stdout ) = $ips->call( "system_inout", $stdin, $path, @args )
The following four functions capture the invoked program's STDERR stream.
Execute a program with the given arguments, returning its exit status and what it wrote on STDERR.
my ( $exitstatus, $stderr ) = $ips->call( "system_err", $path, @args );
Execute a program with the given arguments, passing in a string to its STDIN, and returning its exit status and what it wrote on STDERR.
my ( $exitstatus, $stderr ) = $ips->call( "system_inerr", $stdin, $path, @args );
Execute a program with the given arguments, returning its exit status and what it wrote on STDOUT and STDERR.
my ( $exitstatus, $stdout, $stderr ) = $ips->call( "system_outerr", $path, @args );
Execute a program with the given arguments, passing in a string to its STDIN, and returning its exit status and what it wrote on STDOUT and STDERR.
my ( $exitstatus, $stdout, $stderr ) = $ips->call( "system_inouterr", $stdin, $path, @args )
Paul Evans <leonerd@leonerd.org.uk>
To install IPC::PerlSSH, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::PerlSSH
CPAN shell
perl -MCPAN -e shell install IPC::PerlSSH
For more information on module installation, please visit the detailed CPAN module installation guide.