Learn R Programming

ssh (version 0.9.3)

ssh_exec: Execute Remote Command

Description

Run a command or script on the host while streaming stdout and stderr directly to the client.

Usage

ssh_exec_wait(
  session,
  command = "whoami",
  std_out = stdout(),
  std_err = stderr()
)

ssh_exec_internal(session, command = "whoami", error = TRUE)

Arguments

session

ssh connection created with ssh_connect()

command

The command or script to execute

std_out

callback function, filename, or connection object to handle stdout stream

std_err

callback function, filename, or connection object to handle stderr stream

error

automatically raise an error if the exit status is non-zero

Details

The ssh_exec_wait() function is the remote equivalent of the local sys::exec_wait(). It runs a command or script on the ssh server and streams stdout and stderr to the client to a file or connection. When done it returns the exit status for the remotely executed command.

Similarly ssh_exec_internal() is a small wrapper analogous to sys::exec_internal(). It buffers all stdout and stderr output into a raw vector and returns it in a list along with the exit status. By default this function raises an error if the remote command was unsuccessful.

See Also

Other ssh: scp, ssh_connect(), ssh_credentials, ssh_tunnel()

Examples

Run this code
if (FALSE) {
session <- ssh_connect("dev.opencpu.org")
ssh_exec_wait(session, command = c(
  'curl -O https://cran.r-project.org/src/contrib/jsonlite_1.5.tar.gz',
  'R CMD check jsonlite_1.5.tar.gz',
  'rm -f jsonlite_1.5.tar.gz'
))
ssh_disconnect(session)}

Run the code above in your browser using DataLab