From 466072c81126f50a0632ac95c4765660090e5bd1 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 27 Sep 2011 22:02:33 +0100 Subject: [PATCH] Issue 694: Using "here-document" redirection to wrap commands being passed into sudo --- .../jclouds/compute/callables/RunScriptOnNodeUsingSsh.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSsh.java b/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSsh.java index 8b922bc918..faf05ca9d0 100644 --- a/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSsh.java +++ b/compute/src/main/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSsh.java @@ -44,6 +44,8 @@ import com.google.inject.assistedinject.AssistedInject; * @author Adrian Cole */ public class RunScriptOnNodeUsingSsh implements RunScriptOnNode { + public static final String MARKER = "RUN_SCRIPT_AS_ROOT_SSH"; + @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -102,9 +104,9 @@ public class RunScriptOnNodeUsingSsh implements RunScriptOnNode { public String execAsRoot(String command) { if (node.getCredentials().identity.equals("root")) { } else if (node.getAdminPassword() != null) { - command = String.format("echo '%s'|sudo -S %s", node.getAdminPassword(), command); + command = String.format("sudo -S sh <<'%s'%n%s%n%s%n%s%n", MARKER, node.getAdminPassword(), command, MARKER); } else { - command = "sudo " + command; + command = String.format("sudo sh <<'%s'%n%s%n%s%n", MARKER, command, MARKER); } return command; }