/** * Execute a shell command on a remote vm * * @param vmIpAddress remote vm ip address * @param userName user name * @param password password * @param command shell command */ public void executeCommand(String vmIpAddress, String userName, String password, String command) { SSHExec sshExec = new SSHExec(); sshExec.setUsername(userName); sshExec.setPassword(password); sshExec.setHost(vmIpAddress); sshExec.setCommand(command); sshExec.setProject(PROJECT); sshExec.setTrust(true); log.info("Executing command: {}, on {}", command, vmIpAddress); sshExec.execute(); }
if (getHost() == null) { throw new BuildException("Host is required."); if (getUserInfo().getName() == null) { throw new BuildException("Username is required."); if (getUserInfo().getKeyfile() == null && getUserInfo().getPassword() == null) { throw new BuildException("Password or Keyfile is required."); final StringBuilder output = new StringBuilder(); try { session = openSession(); log("cmd : " + command, Project.MSG_INFO); executeCommand(session, command, output); } else { // read command resource and execute for each command try (final BufferedReader br = new BufferedReader( final Session s = session; br.lines().forEach(cmd -> { log("cmd : " + cmd, Project.MSG_INFO); output.append(cmd).append(" : "); executeCommand(s, cmd, output); output.append("\n"); }); } catch (final IOException e) { if (getFailonerror()) { throw new BuildException(e);
log("Failed to read " + inputFile + " because of: " + e.getMessage(), Project.MSG_WARN); final String inputData = getProject().getProperty(inputProperty); if (inputData != null) { istream = new ByteArrayInputStream(inputData.getBytes()); if (getFailonerror()) { throw new BuildException(TIMEOUT_MESSAGE); log(TIMEOUT_MESSAGE, Project.MSG_ERR); } else { writeToFile(out.toString(), append, outputFile); getProject().setNewProperty(errorProperty, errout.toString()); writeToFile(errout.toString(), appenderr, errorFile); getProject().setNewProperty(resultProperty, Integer.toString(ec)); if (getFailonerror()) { throw new BuildException(msg); log(msg, Project.MSG_ERR); } catch (final JSchException e) { if (e.getMessage().contains("session is down")) { if (getFailonerror()) {