int statusResult = asInt(acquire(new ShellAction(buildRetrieveStatusCommand(), statusOut, statusErr, execTimeout)), -1);
int execResult = asInt(acquire(new ShellAction(buildRunScriptCommand(), out, err, execTimeout)), -1); if (execResult != 0) return execResult; int execDeleteResult = asInt(acquire(new ShellAction(deleteTemporaryFilesCommand(), out, err, pollTimeout)), -1); if (execDeleteResult != 0) { LOG.debug("Problem deleting temporary files of async script on "+SshjTool.this.toString()+" (for "+getSummary()+"): exit status "+execDeleteResult); List<String> pollCommand = buildLongPollCommand(stdoutCount, stderrCount, nextPollTimeout); Duration sshJoinTimeout = nextPollTimeout.add(Duration.TEN_SECONDS); ShellAction action = new ShellAction(pollCommand, countingOut, countingErr, sshJoinTimeout); int statusResult = asInt(acquire(new ShellAction(buildRetrieveStatusCommand(), statusOut, statusErr, execTimeout)), -1);
int execResult = asInt(acquire(new ShellAction(buildRunScriptCommand(), out, err, execTimeout)), -1); if (execResult != 0) return execResult; int execDeleteResult = asInt(acquire(new ShellAction(deleteTemporaryFilesCommand(), out, err, pollTimeout)), -1); if (execDeleteResult != 0) { LOG.debug("Problem deleting temporary files of async script on "+SshjTool.this.toString()+" (for "+getSummary()+"): exit status "+execDeleteResult);
List<String> pollCommand = buildLongPollCommand(stdoutCount, stderrCount, nextPollTimeout); Duration sshJoinTimeout = nextPollTimeout.add(Duration.TEN_SECONDS); ShellAction action = new ShellAction(pollCommand, countingOut, countingErr, sshJoinTimeout);
if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} as script: {}", host, scriptContents); copyToServer(ImmutableMap.of("permissions", "0700"), scriptContents.getBytes(), scriptPath); return asInt(acquire(new ShellAction(buildRunScriptCommand(), out, err, execTimeout)), -1);
public int execShellDirect(Map<String,?> props, List<String> commands, Map<String,?> env) { OutputStream out = getOptionalVal(props, PROP_OUT_STREAM); OutputStream err = getOptionalVal(props, PROP_ERR_STREAM); Duration execTimeout = getOptionalVal(props, PROP_EXEC_TIMEOUT); List<String> cmdSequence = toCommandSequence(commands, env); List<String> allcmds = ImmutableList.<String>builder() .add(getOptionalVal(props, PROP_DIRECT_HEADER)) .addAll(cmdSequence) .add("exit $?") .build(); if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {}: {}", host, allcmds); Integer result = acquire(new ShellAction(allcmds, out, err, execTimeout)); if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} completed: return status {}", host, result); return asInt(result, -1); }
@Override public int run() { String scriptContents = toScript(props, commands, env); if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} as script: {}", host, scriptContents); copyToServer(ImmutableMap.of("permissions", "0700"), scriptContents.getBytes(), scriptPath); return asInt(acquire(new ShellAction(buildRunScriptCommand(), out, err, execTimeout)), -1); } }.run();