summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-02-10 12:43:28 +0000
committerLars Wirzenius <liw@liw.fi>2013-02-10 12:43:28 +0000
commit5e3a3cfd1f325c3c2d346967ed6c2e381f89d546 (patch)
tree7fce2839dc2390b7efd475efa8673342edf209ce
parentc492e2efbaadbd93f077b5dab7c4c8ac8babcec6 (diff)
downloadcliapp-5e3a3cfd1f325c3c2d346967ed6c2e381f89d546.tar.gz
Add cliapp.ssh_runcmd
-rw-r--r--cliapp/__init__.py2
-rw-r--r--cliapp/runcmd.py24
2 files changed, 25 insertions, 1 deletions
diff --git a/cliapp/__init__.py b/cliapp/__init__.py
index 9ab5cc4..6d4040a 100644
--- a/cliapp/__init__.py
+++ b/cliapp/__init__.py
@@ -21,7 +21,7 @@ __version__ = '1.20121216'
from fmt import TextFormat
from settings import (Settings, log_group_name, config_group_name,
perf_group_name)
-from runcmd import runcmd, runcmd_unchecked, shell_quote
+from runcmd import runcmd, runcmd_unchecked, shell_quote, ssh_runcmd
from app import Application, AppException
# The plugin system
diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py
index c8e0281..10b75ef 100644
--- a/cliapp/runcmd.py
+++ b/cliapp/runcmd.py
@@ -221,3 +221,27 @@ def shell_quote(s):
return ''.join(quoted)
+
+def ssh_runcmd(target, argv, **kwargs): # pragma: no cover
+ '''Run command in argv on remote host target.
+
+ This is similar to runcmd, but the command is run on the remote
+ machine. The command is given as an argv array; elements in the
+ array are automatically quoted so they get passed to the other
+ side correctly.
+
+ The target is given as-is to ssh, and may use any syntax ssh
+ accepts.
+
+ Environment variables may or may not be passed to the remote
+ machine: this is dependent on the ssh and sshd configurations.
+ Invoke env(1) explicitly to pass in the variables you need to
+ exist on the other end.
+
+ Pipelines are not supported.
+
+ '''
+
+ local_argv = ['ssh', target, '--'] + map(shell_quote, argv)
+ return runcmd(local_argv, **kwargs)
+