Skip to content

Commit

Permalink
Fix basic SSH commands
Browse files Browse the repository at this point in the history
  • Loading branch information
justinjfu committed Jan 17, 2020
1 parent 96a2570 commit 1552707
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
13 changes: 11 additions & 2 deletions doodad/credentials/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ def get_ssh_bash_cmd(self, cmd):
return prefix + " '%s'"%cmd

def get_ssh_script_cmd(self, script_name, shell_interpreter='bash'):
cmd = self.get_ssh_cmd_prefix()
cmd += "'%s -s' < %s" % (shell_interpreter, script_name)
# The following does not work with archive scripts
# cmd = self.get_ssh_cmd_prefix()
# cmd += "'%s -s' < %s" % (shell_interpreter, script_name)
cmd = "{scp_cmd};" + \
"{ssh_cmd}'{shell_interpreter} ./tmp_script.sh';" + \
"{ssh_cmd}'rm ./tmp_script.sh'"
cmd = cmd.format(
scp_cmd=self.get_scp_cmd(script_name, './tmp_script.sh', src_remote=False),
ssh_cmd=self.get_ssh_cmd_prefix(),
shell_interpreter=shell_interpreter
)
return cmd

def get_scp_cmd(self, source, destination, src_remote=True, recursive=True):
Expand Down
7 changes: 5 additions & 2 deletions doodad/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ def run_script(self, script_filename, dry=False, return_output=False, verbose=Fa
verbose (bool): Verbose mode
return_output (bool): If True, returns stdout from the script as a string.
"""
run_cmd = self._get_run_command(script_filename)
if verbose:
print('Executing command:', run_cmd)
if return_output:
output = shell.call_and_get_output(self._get_run_command(script_filename), shell=True, dry=dry)
output = shell.call_and_get_output(run_cmd, shell=True, dry=dry)
if output:
return output.decode('utf-8')
else:
shell.call(self._get_run_command(script_filename), shell=True, dry=dry, wait=not self.async_run)
shell.call(run_cmd, shell=True, dry=dry, wait=not self.async_run)

def _get_run_command(self, script_filename):
raise NotImplementedError()
Expand Down
2 changes: 1 addition & 1 deletion doodad/test_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def test_mode(self):
launcher = mode.SSHMode(credentials, shell_interpreter='bashy')
self.assertEqual(
launcher._get_run_command('myscript.sh'),
'ssh [email protected] \'bashy -s\' < myscript.sh'
"scp -r myscript.sh [email protected]:./tmp_script.sh;ssh [email protected] 'bashy ./tmp_script.sh';ssh [email protected] 'rm ./tmp_script.sh'"
)

0 comments on commit 1552707

Please sign in to comment.