summaryrefslogtreecommitdiff
path: root/buildscripts/remote_operations.py
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2017-08-23 16:00:39 -0400
committerJonathan Abrahams <jonathan@mongodb.com>2017-08-23 16:00:39 -0400
commit7081a76ac2965bd765b6c372581c81f63c9e6b3c (patch)
tree5d3dd1ae2518d6fd22b223988f900c5f974ab0f6 /buildscripts/remote_operations.py
parenteae3f8ccfa4dacf1f92b31d60281ba60c4fa5462 (diff)
downloadmongo-7081a76ac2965bd765b6c372581c81f63c9e6b3c.tar.gz
SERVER-30699 Shell commands fail for cases with quotes for buildscripts/remote_operations
Diffstat (limited to 'buildscripts/remote_operations.py')
-rwxr-xr-xbuildscripts/remote_operations.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/buildscripts/remote_operations.py b/buildscripts/remote_operations.py
index ce3d8755804..84964b46f77 100755
--- a/buildscripts/remote_operations.py
+++ b/buildscripts/remote_operations.py
@@ -135,15 +135,15 @@ class RemoteOperations(object):
if operation_dir is not None:
operation_param = "cd {}; {}".format(operation_dir, operation_param)
dollar = ""
- if self.use_shell:
- # To ensure any single quotes in operation_param are handled correctly when
+ if re.search("\"|'", operation_param):
+ # To ensure any quotes in operation_param are handled correctly when
# invoking the operation_param, escape with \ and add $ in the front.
# See https://stackoverflow.com/questions/8254120/
# how-to-escape-a-single-quote-in-single-quote-string-in-bash
- if "'" in operation_param:
- operation_param = "{}".format(operation_param.replace("'", "\\'"))
- dollar = "$"
- cmd = "ssh {} {} {}'{}'".format(
+ operation_param = "{}".format(operation_param.replace("'", r"\'"))
+ operation_param = "{}".format(operation_param.replace("\"", r"\""))
+ dollar = "$"
+ cmd = "ssh {} {} /bin/bash -c \"{}'{}'\"".format(
self.ssh_options,
self.user_host,
dollar,
@@ -187,9 +187,10 @@ class RemoteOperations(object):
operation_type, _OPERATIONS))
final_ret = 0
+ buff = ""
for cmd in cmds:
- ret, buff = self._perform_operation(cmd)
- buff += buff
+ ret, new_buff = self._perform_operation(cmd)
+ buff += new_buff
final_ret = final_ret or ret
return final_ret, buff